golang / gddo

Go Doc Dot Org
https://godoc.org
BSD 3-Clause "New" or "Revised" License
1.1k stars 265 forks source link

panic: http: multiple registrations for /debug/requests #553

Closed parkr closed 6 years ago

parkr commented 6 years ago

When running a154dc8b46f4e499724277f2ff2e9b41b959198d gddo-server on golang 1.10.2 in a docker container, I get:

panic: http: multiple registrations for /debug/requests

goroutine 1 [running]:
net/http.(*ServeMux).Handle(0x11c95c0, 0xce7e3d, 0xf, 0xd78080, 0xd166c0)
    /usr/local/go/src/net/http/server.go:2353 +0x239
net/http.(*ServeMux).HandleFunc(0x11c95c0, 0xce7e3d, 0xf, 0xd166c0)
    /usr/local/go/src/net/http/server.go:2368 +0x55
net/http.HandleFunc(0xce7e3d, 0xf, 0xd166c0)
    /usr/local/go/src/net/http/server.go:2380 +0x4b
golang.org/x/net/trace.init.0()
    /go/src/golang.org/x/net/trace/trace.go:115 +0x42

Some googling shows me that this is because golang.org/x/net/trace is imported. This package imports cloud.google.com/go/trace which imports x/net/trace and is deprecated. Is there a way to run this server on golang 1.10.2?

parkr commented 6 years ago

I can't build the gddo-server binary starting with https://github.com/golang/gddo/commit/abcff8962b91e0c6ebbfdeeb6dc963ea6f636e79. cc @dsymonds

Taking a look at https://go-review.googlesource.com/c/gddo/+/114775, the TryBot was not re-run after the first failure. Perhaps the tests are still failing?

parkr commented 6 years ago
FROM golang:1.10.2

RUN go get -d github.com/golang/gddo/gddo-server

RUN cd /go/src/github.com/golang/gddo && \
    git fetch -q origin && \
    git checkout -q --force abcff8962b91e0c6ebbfdeeb6dc963ea6f636e79

RUN go install github.com/golang/gddo/gddo-server

ADD exe/run.sh /usr/bin/docker-entrypoint.sh

CMD /usr/bin/docker-entrypoint.sh

exe/run.sh is:

#!/bin/sh

if [ -z "$REDIS_URL" ]; then
    echo "You must set a REDIS_URL env var" >&2
    exit 1
fi

if [ -z "$HTTP_ADDR" ]; then
    echo "You must set a HTTP_ADDR env var" >&2
    exit 1
fi

/bin/gddo-server \
    --assets /assets \
    --db-server "$REDIS_URL" \
    --db-log \
    --http "$HTTP_ADDR" \
    --robot "9e99" \
    --trust_proxy_headers "$@"
dsymonds commented 6 years ago

Are you able to verify that it worked before abcff89?

I can't see how it could have caused a duplicate HTTP registration (note that godoc.org is currently running this code quite happily). abcff89 adds an explicit dependency on cloud.google.com/go/pubsub, and that (via google.golang.org/grpc) depends on x/net/trace, but gddo-server was already importing cloud.google.com/go/logging and that also imports the grpc package.

dsymonds commented 6 years ago

I can reproduce this, though I still don't understand why it is happening.

github.com/golang/gddo is vendoring golang.org/x/net. It also vendors google.golang.org/grpc, which is the only place that imports golang.org/x/net/trace directly in the gddo repository.

The duplicate registration is coming from a non-vendored golang.org/x/net/trace. The question is: why is the vendored version of that package not being used in the gddo-server build?

shantuo commented 6 years ago

The vendored package broke the build, investigating.

parkr commented 6 years ago

@dsymonds When a vendored package imports another vendored package which is not in its vendor directory, but the importing package's vendor directory (as we have here), is Go smart enough to look in the importing package's vendor directory?

github.com/golang/gddo/gddo-server imports google.golang.org/grpc which imports golang.org/x/net/trace which it does NOT vendor, so it loads from GOPATH

github.com/golang/gddo/gddo-server imports golang.org/x/net/trace which it does vendor, so loads from there

github.com/golang/gddo
  vendor/
    google.golang.org/
      grpc/
    golang.org/
      x/
        net/
          trace/
dsymonds commented 6 years ago

I'm not sure. I don't really use vendoring myself. I expected it would have, though.

arp242 commented 6 years ago

Would someone mind taking a look at this? I tested the patch in #557, and it seems to work well.

Right now, following the instructions in Development Environment Setup won't work, as the go install command errors out. This makes it hard for people to contribute/fix bugs (it took me a while to actually get master running when I was fixing a bug yesterday).

Thanks!