Skip to content

Commit

Permalink
fix panic where closenotify was called from wrong goroutine
Browse files Browse the repository at this point in the history
Previously, this was the result when running a test with go1.6rc2:

    go test github.com/ipfs/go-ipfs/commands/http
    panic: net/http: CloseNotify called after ServeHTTP finished

    goroutine 19 [running]:
    net/http.(*response).CloseNotify(0xc8202ca1a0, 0x0)
        /home/r/go/src/net/http/server.go:1533 +0x9d
    github.com/ipfs/go-ipfs/commands/http.internalHandler.ServeHTTP.func2(0x7f42c9d1d180, 0xc8202ca1a0, 0x7f42c9d66e90, 0xc8200f0380, 0xc8201d40d0)
        /home/r/src/github.com/ipfs/go-ipfs/commands/http/handler.go:143 +0x39
    created by github.com/ipfs/go-ipfs/commands/http.internalHandler.ServeHTTP
        /home/r/src/github.com/ipfs/go-ipfs/commands/http/handler.go:147 +0x49d
    FAIL	github.com/ipfs/go-ipfs/commands/http	0.013s

I had also encountered this panic when trying to use the webui.

License: MIT
Signed-off-by: Robert Carlsen <[email protected]>
  • Loading branch information
rwcarlsen committed Feb 8, 2016
1 parent 1aeec4a commit ed23d99
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithCancel(node.Context())
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
clientGone := cn.CloseNotify()
go func() {
select {
case <-cn.CloseNotify():
case <-clientGone:
case <-ctx.Done():
}
cancel()
Expand Down

0 comments on commit ed23d99

Please sign in to comment.