mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
fix deadlock when closing the server and the connection at the same time
This commit is contained in:
parent
b7652887d2
commit
4c25cea9ec
3 changed files with 6 additions and 1 deletions
|
@ -238,6 +238,10 @@ func (h *packetHandlerMap) SetServer(s unknownPacketHandler) {
|
|||
|
||||
func (h *packetHandlerMap) CloseServer() {
|
||||
h.mutex.Lock()
|
||||
if h.server == nil {
|
||||
h.mutex.Unlock()
|
||||
return
|
||||
}
|
||||
h.server = nil
|
||||
var wg sync.WaitGroup
|
||||
for _, handler := range h.handlers {
|
||||
|
|
|
@ -251,6 +251,7 @@ var _ = Describe("Packet Handler Map", func() {
|
|||
})
|
||||
|
||||
It("closes all server sessions", func() {
|
||||
handler.SetServer(NewMockUnknownPacketHandler(mockCtrl))
|
||||
clientSess := NewMockPacketHandler(mockCtrl)
|
||||
clientSess.EXPECT().getPerspective().Return(protocol.PerspectiveClient)
|
||||
serverSess := NewMockPacketHandler(mockCtrl)
|
||||
|
|
|
@ -274,12 +274,12 @@ func (s *baseServer) accept(ctx context.Context) (quicSession, error) {
|
|||
|
||||
// Close the server
|
||||
func (s *baseServer) Close() error {
|
||||
s.sessionHandler.CloseServer()
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
if s.closed {
|
||||
return nil
|
||||
}
|
||||
s.sessionHandler.CloseServer()
|
||||
if s.serverError == nil {
|
||||
s.serverError = errors.New("server closed")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue