Skip to content

net/http: pc close panics #60862

Closed as not planned
Closed as not planned
@karitham

Description

@karitham

What version of Go are you using (go version)?

❯ go version
go version go1.20.4 linux/amd64

Does this issue reproduce with the latest release?

Yes, it reproduces with all the versions I tried, which include 1.20.5, 1.20.4 and 1.19.10

What operating system and processor architecture are you using (go env)?

go env Output
❯ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/kram/.cache/go-build"
GOENV="/home/kram/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/kram/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/kram/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/kram/dev/work/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/nix-shell.eWT3Zb/go-build726875218=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm running an HTTP server, read the request and respond to the request. The moment my handler exits. net/http panics.

It still writes the response back without issue, but the server panics after that and dies; it flushes the full response, has issues after that.

I'm having trouble reproducing the issue and debugging it properly, and can't find anything in my code that would relate to this.

The server is using ListenAndServe, like this

server := http.Server{
	Handler: router,
	Addr:    ":3804",
}

if err := server.ListenAndServe(); err != nil {
	panic(err) // never gets called
}

What did you expect to see?

My server staying alive, or maybe the stack trace pointing at something I am doing wrong.

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x9175dd]

goroutine 49 [running]:
net/http.(*persistConn).closeLocked(0xc00035a120, {0x27a2120, 0xc0000aac30})
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/net/http/transport.go:2732 +0x21d
net/http.(*persistConn).close(0xc00035a120, {0x27a2120, 0xc0000aac30})
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/net/http/transport.go:2717 +0xac
net/http.(*persistConn).readLoop.func1()
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/net/http/transport.go:2075 +0x50
panic({0x21ef260, 0x32c2b30})
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/runtime/panic.go:890 +0x263
net/http.(*persistConn).Read(0xc00035a120, {0xc0004fc000, 0x1000, 0x1000})
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/net/http/transport.go:1943 +0xea
bufio.(*Reader).fill(0xc0006d6660)
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/bufio/bufio.go:106 +0x2ab
bufio.(*Reader).Peek(0xc0006d6660, 0x1)
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/bufio/bufio.go:144 +0xd2
net/http.(*persistConn).readLoop(0xc00035a120)
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/net/http/transport.go:2107 +0x2c8
created by net/http.(*Transport).dialConn
        /nix/store/kfpv1z26wn481yv5z1vzakla8fllhggn-go-1.20.4/share/go/src/net/http/transport.go:1765 +0x2586
exit status 2

Similar stack traces on all versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions