try to fix http2 panic (#54)

This commit is contained in:
ginuerzh
2025-08-21 22:12:19 +08:00
parent d5683e9138
commit a65b7a059a
2 changed files with 10 additions and 1 deletions
+7
View File
@@ -13,6 +13,7 @@ type conn struct {
raddr net.Addr
ctx context.Context
cancel context.CancelFunc
closed chan struct{}
}
func (c *conn) Read(b []byte) (n int, err error) {
@@ -27,6 +28,12 @@ func (c *conn) Close() error {
if c.cancel != nil {
c.cancel()
}
select {
case <-c.closed:
default:
close(c.closed)
}
return nil
}
+3 -1
View File
@@ -178,6 +178,7 @@ func (l *http2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
raddr: remoteAddr,
ctx: ctx,
cancel: cancel,
closed: make(chan struct{}),
}
select {
@@ -187,5 +188,6 @@ func (l *http2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
return
}
<-ctx.Done()
// NOTE: we need to wait for conn closed, or the connection will be closed.
<-conn.closed
}