try to fix http2 panic (#54)
This commit is contained in:
@@ -13,6 +13,7 @@ type conn struct {
|
|||||||
raddr net.Addr
|
raddr net.Addr
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
closed chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conn) Read(b []byte) (n int, err error) {
|
func (c *conn) Read(b []byte) (n int, err error) {
|
||||||
@@ -27,6 +28,12 @@ func (c *conn) Close() error {
|
|||||||
if c.cancel != nil {
|
if c.cancel != nil {
|
||||||
c.cancel()
|
c.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-c.closed:
|
||||||
|
default:
|
||||||
|
close(c.closed)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ func (l *http2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
raddr: remoteAddr,
|
raddr: remoteAddr,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
|
closed: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@@ -187,5 +188,6 @@ func (l *http2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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