Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: fix deadlock when closing concurrently with transport #4332

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
server: fix deadlock when closing concurrently with transport
  • Loading branch information
sukunrt committed Feb 17, 2024
commit 70c821348920535845de489a6b759b32df45419f
22 changes: 13 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type baseServer struct {
protocol.Version,
) quicConn

closeOnce sync.Once
closeMx sync.Mutex
errorChan chan struct{} // is closed when the server is closed
closeErr error
running chan struct{} // closed as soon as run() returns
Expand Down Expand Up @@ -338,15 +338,19 @@ func (s *baseServer) Close() error {
}

func (s *baseServer) close(e error, notifyOnClose bool) {
s.closeOnce.Do(func() {
s.closeErr = e
close(s.errorChan)
s.closeMx.Lock()
if s.closeErr != nil {
s.closeMx.Unlock()
return
}
s.closeErr = e
close(s.errorChan)
<-s.running
s.closeMx.Unlock()

<-s.running
if notifyOnClose {
s.onClose()
}
})
if notifyOnClose {
s.onClose()
}
}

// Addr returns the server's network address
Expand Down
Loading