mirror of https://github.com/tidwall/redcon.git
fix: race condition in initialisation of server
This commit is contained in:
parent
8b671291b8
commit
c746dbc05b
|
@ -235,12 +235,14 @@ func Serve(ln net.Listener,
|
||||||
closed func(conn Conn, err error),
|
closed func(conn Conn, err error),
|
||||||
) error {
|
) error {
|
||||||
s := newServer()
|
s := newServer()
|
||||||
|
s.mu.Lock()
|
||||||
s.net = ln.Addr().Network()
|
s.net = ln.Addr().Network()
|
||||||
s.laddr = ln.Addr().String()
|
s.laddr = ln.Addr().String()
|
||||||
s.ln = ln
|
s.ln = ln
|
||||||
s.handler = handler
|
s.handler = handler
|
||||||
s.accept = accept
|
s.accept = accept
|
||||||
s.closed = closed
|
s.closed = closed
|
||||||
|
s.mu.Unlock()
|
||||||
return serve(s)
|
return serve(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +298,9 @@ func (s *Server) ListenServeAndSignal(signal chan error) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
s.mu.Lock()
|
||||||
s.ln = ln
|
s.ln = ln
|
||||||
|
s.mu.Unlock()
|
||||||
if signal != nil {
|
if signal != nil {
|
||||||
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.
|
// Serve serves incoming connections with the given net.Listener.
|
||||||
func (s *Server) Serve(ln net.Listener) error {
|
func (s *Server) Serve(ln net.Listener) error {
|
||||||
|
s.mu.Lock()
|
||||||
s.ln = ln
|
s.ln = ln
|
||||||
s.net = ln.Addr().Network()
|
s.net = ln.Addr().Network()
|
||||||
s.laddr = ln.Addr().String()
|
s.laddr = ln.Addr().String()
|
||||||
|
s.mu.Unlock()
|
||||||
return serve(s)
|
return serve(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +327,9 @@ func (s *TLSServer) ListenServeAndSignal(signal chan error) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
s.mu.Lock()
|
||||||
s.ln = ln
|
s.ln = ln
|
||||||
|
s.mu.Unlock()
|
||||||
if signal != nil {
|
if signal != nil {
|
||||||
signal <- nil
|
signal <- nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue