check if connection is closed before returning it from Accept
It could have been sitting around for a while.
@@ -125,9 +125,12 @@ func (l *listener) handleIncoming() {
// Accept accepts a connection.
func (l *listener) Accept() (transport.Conn, error) {
- if c, ok := <-l.incoming; ok {
+ for c := range l.incoming {
+ // Could have been sitting there for a while.
+ if !c.IsClosed() {
return c, nil
}
+ }
return nil, l.err
}
