pieterlouw / caddy-grpc

grpc plugin for Caddy Server
Apache License 2.0
48 stars 15 forks source link

Plugin crashes caddy 0.10.4 builds #1

Open klingtnet opened 7 years ago

klingtnet commented 7 years ago

Caddy 0.10.4 fails to start because there are multiple registrations for /debug/requests. A build without this plugin runs fine.

Steps to reproduce the issue:

$ curl -Lsf 'https://caddyserver.com/download/linux/amd64?plugins=dns,http.authz,http.awslambda,http.cgi,http.cors,http.datadog,http.expires,http.filemanager,http.filter,http.git,http.gopkg,http.grpc,http.hugo,http.ipfilter,http.jwt,http.login,http.mailout,http.minify,http.prometheus,http.proxyprotocol,http.ratelimit,http.realip,http.reauth,http.upload,net,tls.dns.cloudflare,tls.dns.digitalocean,tls.dns.dnsimple,tls.dns.dnspod,tls.dns.dyn,tls.dns.exoscale,tls.dns.gandi,tls.dns.googlecloud,tls.dns.linode,tls.dns.namecheap,tls.dns.ovh,tls.dns.rackspace,tls.dns.rfc2136,tls.dns.route53,tls.dns.vultr' | tar -xvz caddy && ./caddy
panic: http: multiple registrations for /debug/requests

goroutine 1 [running]:
net/http.(*ServeMux).Handle(0x1e5fc60, 0x14938e2, 0xf, 0x1be32e0, 0x14e6c40)
    /usr/local/go/src/net/http/server.go:2254 +0x610
net/http.(*ServeMux).HandleFunc(0x1e5fc60, 0x14938e2, 0xf, 0x14e6c40)
    /usr/local/go/src/net/http/server.go:2286 +0x55
net/http.HandleFunc(0x14938e2, 0xf, 0x14e6c40)
    /usr/local/go/src/net/http/server.go:2298 +0x4b
golang.org/x/net/trace.init.1()
    /gopath/src/golang.org/x/net/trace/trace.go:115 +0x42
golang.org/x/net/trace.init()
    /gopath/src/golang.org/x/net/trace/trace_go17.go:22 +0x1cd
google.golang.org/grpc.init()
    /gopath/src/google.golang.org/grpc/trace.go:105 +0x82
github.com/improbable-eng/grpc-web/go/grpcweb.init()
    /gopath/src/github.com/improbable-eng/grpc-web/go/grpcweb/wrapper.go:115 +0x62
github.com/pieterlouw/caddy-grpc.init()
    src/github.com/pieterlouw/caddy-grpc/setup.go:90 +0x52
github.com/mholt/caddy/caddy/caddymain.init()
    src/github.com/mholt/caddy/caddy/caddymain/run.go:276 +0xd4
main.init()
    src/github.com/mholt/caddy/caddy/main.go:15 +0x44

Caddy starts fine without this plugin :

$ curl -Lsf 'https://caddyserver.com/download/linux/amd64?plugins=dns,http.authz,http.awslambda,http.cgi,http.cors,http.datadog,http.expires,http.filemanager,http.filter,http.git,http.gopkg,http.hugo,http.ipfilter,http.jwt,http.login,http.mailout,http.minify,http.prometheus,http.proxyprotocol,http.ratelimit,http.realip,http.reauth,http.upload,net,tls.dns.cloudflare,tls.dns.digitalocean,tls.dns.dnsimple,tls.dns.dnspod,tls.dns.dyn,tls.dns.exoscale,tls.dns.gandi,tls.dns.googlecloud,tls.dns.linode,tls.dns.namecheap,tls.dns.ovh,tls.dns.rackspace,tls.dns.rfc2136,tls.dns.route53,tls.dns.vultr' | tar -xvz caddy && ./caddy 
caddy
Activating privacy features... done.
http://:2015
WARNING: File descriptor limit 1024 is too low for production servers. At least 8192 is recommended. Fix with "ulimit -n 8192".
pieterlouw commented 7 years ago

Hi @klingtnet,

It seems the problem is there's another plugin that uses grpc and https://github.com/grpc/grpc-go/blob/master/trace.go imports golang.org/x/net/trace which in turn registers /debug/requests and /debug/events handlers in it's init() function to the Go default http muxer. (https://github.com/golang/net/blob/master/trace/trace.go#L112-L117)

I'm not sure yet if it will be possible to fix it from within my plugin as the problem is deeply entrenched in the grpc package.

I've established that it's the dns server type that's also using grpc, so a temporary solution would be to exclude the other plugin if you want to use one of them(exclude dns if you want to use grpc or vice versa ). Obviously this is not ideal if you want to use both plugins. I have tested it by excluding dns plugin as follows:

curl -Lsf 'https://caddyserver.com/download/linux/amd64?plugins=http.authz,http.awslambda,http.cgi,http.cors,http.datadog,http.expires,http.filemanager,http.filter,http.git,http.gopkg,http.grpc,http.hugo,http.ipfilter,http.jwt,http.login,http.mailout,http.minify,http.prometheus,http.proxyprotocol,http.ratelimit,http.realip,http.reauth,http.upload,net,tls.dns.cloudflare,tls.dns.digitalocean,tls.dns.dnsimple,tls.dns.dnspod,tls.dns.dyn,tls.dns.exoscale,tls.dns.gandi,tls.dns.googlecloud,tls.dns.linode,tls.dns.namecheap,tls.dns.ovh,tls.dns.rackspace,tls.dns.rfc2136,tls.dns.route53,tls.dns.vultr' | tar -xvz caddy && ./caddy

Pieter

linquize commented 5 years ago

If I add all the plugins as well as github.com/pieterlouw/caddy-grpc,

panic: /debug/requests is already registered. You may have two independent copies of golang.org/x/net/trace in your binary, trying to maintain separate state. This may involve a vendored copy of golang.org/x/net/trace.