From 3e87ca0862df0885badf4c7f778ffc263dfccffc Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Mon, 8 May 2023 23:11:29 -0700 Subject: [PATCH] quic virtual listener: don't panic when quic-go's accept call errors (#2276) --- p2p/transport/quic/virtuallistener.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/p2p/transport/quic/virtuallistener.go b/p2p/transport/quic/virtuallistener.go index fc6373f857..36c11c6619 100644 --- a/p2p/transport/quic/virtuallistener.go +++ b/p2p/transport/quic/virtuallistener.go @@ -46,8 +46,9 @@ type acceptVal struct { type acceptLoopRunner struct { acceptSem chan struct{} - muxerMu sync.Mutex - muxer map[quic.VersionNumber]chan acceptVal + muxerMu sync.Mutex + muxer map[quic.VersionNumber]chan acceptVal + muxerClosed bool } func (r *acceptLoopRunner) AcceptForVersion(v quic.VersionNumber) chan acceptVal { @@ -68,6 +69,11 @@ func (r *acceptLoopRunner) RmAcceptForVersion(v quic.VersionNumber) { r.muxerMu.Lock() defer r.muxerMu.Unlock() + if r.muxerClosed { + // Already closed, all versions are removed + return + } + ch, ok := r.muxer[v] if !ok { panic("expected chan in accept muxer") @@ -79,6 +85,7 @@ func (r *acceptLoopRunner) RmAcceptForVersion(v quic.VersionNumber) { func (r *acceptLoopRunner) sendErrAndClose(err error) { r.muxerMu.Lock() defer r.muxerMu.Unlock() + r.muxerClosed = true for k, ch := range r.muxer { select { case ch <- acceptVal{err: err}: