mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 21: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() {
|
func (h *packetHandlerMap) CloseServer() {
|
||||||
h.mutex.Lock()
|
h.mutex.Lock()
|
||||||
|
if h.server == nil {
|
||||||
|
h.mutex.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
h.server = nil
|
h.server = nil
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, handler := range h.handlers {
|
for _, handler := range h.handlers {
|
||||||
|
|
|
@ -251,6 +251,7 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("closes all server sessions", func() {
|
It("closes all server sessions", func() {
|
||||||
|
handler.SetServer(NewMockUnknownPacketHandler(mockCtrl))
|
||||||
clientSess := NewMockPacketHandler(mockCtrl)
|
clientSess := NewMockPacketHandler(mockCtrl)
|
||||||
clientSess.EXPECT().getPerspective().Return(protocol.PerspectiveClient)
|
clientSess.EXPECT().getPerspective().Return(protocol.PerspectiveClient)
|
||||||
serverSess := NewMockPacketHandler(mockCtrl)
|
serverSess := NewMockPacketHandler(mockCtrl)
|
||||||
|
|
|
@ -274,12 +274,12 @@ func (s *baseServer) accept(ctx context.Context) (quicSession, error) {
|
||||||
|
|
||||||
// Close the server
|
// Close the server
|
||||||
func (s *baseServer) Close() error {
|
func (s *baseServer) Close() error {
|
||||||
|
s.sessionHandler.CloseServer()
|
||||||
s.mutex.Lock()
|
s.mutex.Lock()
|
||||||
defer s.mutex.Unlock()
|
defer s.mutex.Unlock()
|
||||||
if s.closed {
|
if s.closed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.sessionHandler.CloseServer()
|
|
||||||
if s.serverError == nil {
|
if s.serverError == nil {
|
||||||
s.serverError = errors.New("server closed")
|
s.serverError = errors.New("server closed")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue