mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
make sure the server is stopped before closing all server sessions
This commit is contained in:
parent
f1500db062
commit
aea8f7345b
2 changed files with 10 additions and 8 deletions
16
server.go
16
server.go
|
@ -274,25 +274,27 @@ 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 {
|
||||
s.mutex.Unlock()
|
||||
return nil
|
||||
}
|
||||
if s.serverError == nil {
|
||||
s.serverError = errors.New("server closed")
|
||||
}
|
||||
var err error
|
||||
// If the server was started with ListenAddr, we created the packet conn.
|
||||
// We need to close it in order to make the go routine reading from that conn return.
|
||||
if s.createdPacketConn {
|
||||
err = s.sessionHandler.Destroy()
|
||||
}
|
||||
createdPacketConn := s.createdPacketConn
|
||||
s.closed = true
|
||||
close(s.errorChan)
|
||||
s.mutex.Unlock()
|
||||
|
||||
<-s.running
|
||||
return err
|
||||
s.sessionHandler.CloseServer()
|
||||
if createdPacketConn {
|
||||
return s.sessionHandler.Destroy()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *baseServer) setCloseError(e error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue