Merge pull request #3472 from sangheee/develop

fix: negative WaitGroup counter has not been resolved yet.
This commit is contained in:
astaxie 2019-01-08 23:54:40 +08:00 committed by GitHub
commit 80aabdd372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -28,12 +28,11 @@ func (c *graceConn) Close() (err error) {
}()
c.m.Lock()
defer c.m.Unlock()
if c.closed {
c.m.Unlock()
return
}
c.server.wg.Done()
c.closed = true
c.m.Unlock()
return c.Conn.Close()
}

View File

@ -34,6 +34,11 @@ type Server struct {
// creating a new service goroutine for each.
// The service goroutines read requests and then call srv.Handler to reply to them.
func (srv *Server) Serve() (err error) {
defer func() {
if r := recover(); r != nil {
log.Println("wait group counter is negative", r)
}
}()
srv.state = StateRunning
err = srv.Server.Serve(srv.GraceListener)
log.Println(syscall.Getpid(), "Waiting for connections to finish...")