From 8f7f9df910d82e4df1cb835caa5a524952ccc9fb Mon Sep 17 00:00:00 2001 From: Naitik Shah Date: Wed, 3 Apr 2013 18:11:40 -0700 Subject: [PATCH] drop connections that come in between a close and an accept race this is bad, but worse is the current logic which can sometimes hit a nil counter channel. --- grace.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/grace.go b/grace.go index bf04ea1..a618ba0 100644 --- a/grace.go +++ b/grace.go @@ -135,11 +135,16 @@ func (l *listener) Accept() (net.Conn, error) { } return nil, err } - l.counter <- inc - return conn{ - Conn: c, - counter: l.counter, - }, nil + select { + case <-l.allClosed: + c.Close() + return nil, ErrAlreadyClosed + case l.counter <- inc: + return conn{ + Conn: c, + counter: l.counter, + }, nil + } } panic("not reached") }