Skip to content

x/net/http2/h2c panic #67168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chenjie199234 opened this issue May 4, 2024 · 3 comments
Closed

x/net/http2/h2c panic #67168

chenjie199234 opened this issue May 4, 2024 · 3 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@chenjie199234
Copy link

chenjie199234 commented May 4, 2024

Go version

Go Version:1.22.2
build host:windows/amd64
build target:linux/amd64
run host:linux/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
go: stripping unprintable or unescapable characters from %"GOBIN"%
set GOBIN=C:\Users\������\Desktop\Go\bin
go: stripping unprintable or unescapable characters from %"GOCACHE"%
set GOCACHE=C:\Users\������\Desktop\Go\cache
go: stripping unprintable or unescapable characters from %"GOENV"%
set GOENV=C:\Users\������\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
go: stripping unprintable or unescapable characters from %"GOMODCACHE"%
set GOMODCACHE=C:\Users\������\Desktop\Go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
go: stripping unprintable or unescapable characters from %"GOPATH"%
set GOPATH=C:\Users\������\Desktop\Go
set GOPRIVATE=
set GOPROXY=direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
go: stripping unprintable or unescapable characters from %"GOGCCFLAGS"%
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\������\AppData\Local\Temp\go-build1138275416=/tmp/go-build -gno-record-gcc-switches

What did you do?

use x/net/h2c to start a h2c http server

h2c.NewHandler(r, &http2.Server{
	NewWriteScheduler:         func() http2.WriteScheduler { return http2.NewPriorityWriteScheduler(nil) },
	IdleTimeout:               time.Second * 5,
	MaxDecoderHeaderTableSize: 2048,
	MaxEncoderHeaderTableSize: 2048,
})

What did you see happen?

http: panic serving xxx.xxx.xxx.xxx:xxx: runtime error: invalid memory address or nil pointer dereference
goroutine 1028135 [running]:
net/http.(*conn).serve.func1()
	C:/Program Files/Go/src/net/http/server.go:1898 +0xbe
panic({0x1a14840?, 0x2dc6780?})
	C:/Program Files/Go/src/runtime/panic.go:770 +0x132
time.(*Timer).Reset(0x1a06a40?, 0xc00024dc50?)
	C:/Program Files/Go/src/time/sleep.go:135 +0xe
golang.org/x/net/http2.(*serverConn).closeStream(0xc00033ed00, 0xc0004d43c0, {0x1f847e0, 0x2dc8b20})
	C:/Users/陈杰/Desktop/Go/pkg/mod/golang.org/x/net@v0.24.0/http2/server.go:1642 +0x17b
golang.org/x/net/http2.(*serverConn).closeAllStreamsOnConnClose(0xc00033ed00)
	C:/Users/陈杰/Desktop/Go/pkg/mod/golang.org/x/net@v0.24.0/http2/server.go:862 +0xaa
golang.org/x/net/http2.(*serverConn).serve(0xc00033ed00)
	C:/Users/陈杰/Desktop/Go/pkg/mod/golang.org/x/net@v0.24.0/http2/server.go:919 +0x6ea
golang.org/x/net/http2.(*Server).ServeConn(0xc0004e2be0, {0x1fa57b0, 0xc0003c8018}, 0xc0005239b0)
	C:/Users/陈杰/Desktop/Go/pkg/mod/golang.org/x/net@v0.24.0/http2/server.go:532 +0xbad
golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP({{0x1f85380?, 0xc0002513e0?}, 0xc0004e2be0?}, {0x1f92380, 0xc000134620}, 0xc0001c0240)
	C:/Users/陈杰/Desktop/Go/pkg/mod/golang.org/x/net@v0.24.0/http2/h2c/h2c.go:116 +0x649
net/http.serverHandler.ServeHTTP({0xc00024dad0?}, {0x1f92380?, 0xc000134620?}, 0x6?)
	C:/Program Files/Go/src/net/http/server.go:3137 +0x8e
net/http.(*conn).serve(0xc00015ee10, {0x1f9f2a0, 0xc00024da70})
	C:/Program Files/Go/src/net/http/server.go:2039 +0x5e8
created by net/http.(*Server).Serve in goroutine 58
	C:/Program Files/Go/src/net/http/server.go:3285 +0x4b4

What did you expect to see?

no panic

@gopherbot gopherbot added this to the Unreleased milestone May 4, 2024
@chenjie199234 chenjie199234 changed the title x/net/h2c x/net/h2c panic May 4, 2024
@chenjie199234 chenjie199234 changed the title x/net/h2c panic x/net/http2/h2c panic May 4, 2024
@seankhliao
Copy link
Member

do you have a way to reproduce this?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 4, 2024
@chenjie199234
Copy link
Author

@seankhliao i don't think we nee a reproduce.
follow the panic stack info,we can find the reason.

we create a Conn here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L402
then we serve the conn here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L888
we setted idletimeout,so it will be inited here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L928
but the conn returned before the idletimer be inited at here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L917
so the idletimer is nil now!
when the conn is closing,we will go into here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L892
and we will close all the streams here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L862
the stream will be deleted from the conn here:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L1643
when last stream be deleted(in this case we only have 1 stream,the not prepared one):
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L1643
then the code trying to close the idletimer but the idletimer is not inited,it is nil:
https://github.com/golang/net/blob/b20cd5933aa9ba90f6299e6c2cbb59733434636e/http2/server.go#L1647

we need to add a nil check before close it

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/584255 mentions this issue: http2: avoid panic on h2c upgrade failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants