Fix deadlock when GracefulStop()ing multiple times

Fixes #793.
This commit is contained in:
Tamir Duberstein
2016-07-29 12:26:26 -04:00
parent f5118cfac7
commit 069ed42115
2 changed files with 22 additions and 1 deletions

View File

@ -798,7 +798,7 @@ func (s *Server) Stop() {
func (s *Server) GracefulStop() {
s.mu.Lock()
if s.drain == true || s.conns == nil {
s.mu.Lock()
s.mu.Unlock()
return
}
s.drain = true

View File

@ -553,6 +553,27 @@ func testTimeoutOnDeadServer(t *testing.T, e env) {
awaitNewConnLogOutput()
}
func TestServerGracefulStopIdempotent(t *testing.T) {
defer leakCheck(t)()
for _, e := range listTestEnv() {
if e.name == "handler-tls" {
continue
}
testServerGracefulStopIdempotent(t, e)
}
}
func testServerGracefulStopIdempotent(t *testing.T, e env) {
te := newTest(t, e)
te.userAgent = testAppUA
te.startServer(&testServer{security: e.security})
defer te.tearDown()
for i := 0; i < 3; i++ {
te.srv.GracefulStop()
}
}
func TestServerGoAway(t *testing.T) {
defer leakCheck(t)()
for _, e := range listTestEnv() {