fix a race condition in quic.Server

This commit is contained in:
Lucas Clemente
2016-06-02 21:21:41 +02:00
parent bd228ffe27
commit 45554e67c4

View File

@@ -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
}