Merge pull request #62 from tomarrell/master

fix: race condition in initialisation of server
This commit is contained in:
Josh Baker 2023-01-20 09:11:59 -07:00 committed by GitHub
commit d05da895e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -235,12 +235,14 @@ func Serve(ln net.Listener,
closed func(conn Conn, err error),
) error {
s := newServer()
s.mu.Lock()
s.net = ln.Addr().Network()
s.laddr = ln.Addr().String()
s.ln = ln
s.handler = handler
s.accept = accept
s.closed = closed
s.mu.Unlock()
return serve(s)
}
@ -296,7 +298,9 @@ func (s *Server) ListenServeAndSignal(signal chan error) error {
}
return err
}
s.mu.Lock()
s.ln = ln
s.mu.Unlock()
if signal != nil {
signal <- nil
}
@ -305,9 +309,11 @@ func (s *Server) ListenServeAndSignal(signal chan error) error {
// Serve serves incoming connections with the given net.Listener.
func (s *Server) Serve(ln net.Listener) error {
s.mu.Lock()
s.ln = ln
s.net = ln.Addr().Network()
s.laddr = ln.Addr().String()
s.mu.Unlock()
return serve(s)
}
@ -321,7 +327,9 @@ func (s *TLSServer) ListenServeAndSignal(signal chan error) error {
}
return err
}
s.mu.Lock()
s.ln = ln
s.mu.Unlock()
if signal != nil {
signal <- nil
}