forked from quic-go/quic-go
fix a race condition in quic.Server
This commit is contained in:
10
server.go
10
server.go
@@ -24,7 +24,9 @@ type packetHandler interface {
|
||||
// A Server of QUIC
|
||||
type Server struct {
|
||||
addr *net.UDPAddr
|
||||
conn *net.UDPConn
|
||||
|
||||
conn *net.UDPConn
|
||||
connMutex sync.Mutex
|
||||
|
||||
signer crypto.Signer
|
||||
scfg *handshake.ServerConfig
|
||||
@@ -74,7 +76,9 @@ func (s *Server) ListenAndServe() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.connMutex.Lock()
|
||||
s.conn = conn
|
||||
s.connMutex.Unlock()
|
||||
|
||||
for {
|
||||
data := make([]byte, protocol.MaxPacketSize)
|
||||
@@ -103,6 +107,10 @@ func (s *Server) Close() error {
|
||||
}
|
||||
}
|
||||
s.sessionsMutex.Unlock()
|
||||
|
||||
s.connMutex.Lock()
|
||||
defer s.connMutex.Unlock()
|
||||
|
||||
if s.conn == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user