1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 17:30:56 +00:00

recover for conn.Close fix #1333

This commit is contained in:
astaxie 2016-01-04 23:34:35 +08:00
parent 5c18d02b17
commit f7ef4aa7e5

View File

@ -1,13 +1,28 @@
package grace package grace
import "net" import (
"errors"
"net"
)
type graceConn struct { type graceConn struct {
net.Conn net.Conn
server *Server server *Server
} }
func (c graceConn) Close() error { func (c graceConn) Close() (err error) {
defer func() {
if r := recover(); r != nil {
switch x := r.(type) {
case string:
err = errors.New(x)
case error:
err = x
default:
err = errors.New("Unknown panic")
}
}
}()
c.server.wg.Done() c.server.wg.Done()
return c.Conn.Close() return c.Conn.Close()
} }