try to fix http2 panic (#54)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user