mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 14:51:29 +00:00
Merge pull request #2717 from huwenbo/master
fix panic sync: negative WaitGroup counter
This commit is contained in:
commit
f2925978f1
@ -3,14 +3,17 @@ package grace
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type graceConn struct {
|
type graceConn struct {
|
||||||
net.Conn
|
net.Conn
|
||||||
server *Server
|
server *Server
|
||||||
|
m sync.Mutex
|
||||||
|
closed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c graceConn) Close() (err error) {
|
func (c *graceConn) Close() (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
switch x := r.(type) {
|
switch x := r.(type) {
|
||||||
@ -23,6 +26,14 @@ func (c graceConn) Close() (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
c.m.Lock()
|
||||||
|
if c.closed {
|
||||||
|
c.m.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
c.server.wg.Done()
|
c.server.wg.Done()
|
||||||
|
c.closed = true
|
||||||
|
c.m.Unlock()
|
||||||
return c.Conn.Close()
|
return c.Conn.Close()
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ func (gl *graceListener) Accept() (c net.Conn, err error) {
|
|||||||
tc.SetKeepAlive(true)
|
tc.SetKeepAlive(true)
|
||||||
tc.SetKeepAlivePeriod(3 * time.Minute)
|
tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||||
|
|
||||||
c = graceConn{
|
c = &graceConn{
|
||||||
Conn: tc,
|
Conn: tc,
|
||||||
server: gl.server,
|
server: gl.server,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user