Skip to content

Commit

Permalink
quic virtual listener: don't panic when quic-go's accept call errors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo authored and marten-seemann committed May 9, 2023
1 parent 6a96cb0 commit 671d363
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions p2p/transport/quic/virtuallistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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}:
Expand Down

0 comments on commit 671d363

Please sign in to comment.