mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 20:09:41 +01:00
server: Add a mutex to kill a very small, bad race
This commit is contained in:
parent
835187a736
commit
1812edb2db
@ -68,6 +68,7 @@ type Server struct {
|
||||
store buntdb.DB
|
||||
idle chan *Client
|
||||
limits Limits
|
||||
listenerEventActMutex sync.Mutex
|
||||
listenerUpdateMutex sync.Mutex
|
||||
listeners map[string]ListenerInterface
|
||||
monitoring map[string][]Client
|
||||
@ -341,6 +342,11 @@ func (s *Server) createListener(addr string, tlsMap map[string]*tls.Config) {
|
||||
|
||||
select {
|
||||
case event := <-s.listeners[addr].Events:
|
||||
// this is used to confirm that whoever passed us this event has closed the existing listener correctly (in an attempt to get us to notice the event).
|
||||
// this is required to keep REHASH from having a very small race possibility of killing the primary listener
|
||||
s.listenerEventActMutex.Lock()
|
||||
s.listenerEventActMutex.Unlock()
|
||||
|
||||
if event.Type == DestroyListener {
|
||||
// listener should already be closed, this is just for safety
|
||||
listener.Close()
|
||||
@ -922,6 +928,7 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
}
|
||||
}
|
||||
|
||||
server.listenerEventActMutex.Lock()
|
||||
if exists {
|
||||
// update old listener
|
||||
fmt.Println("refreshing", addr)
|
||||
@ -938,6 +945,8 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||
}
|
||||
// force listener to apply the event right away
|
||||
server.listeners[addr].Listener.Close()
|
||||
|
||||
server.listenerEventActMutex.Unlock()
|
||||
}
|
||||
|
||||
for _, newaddr := range config.Server.Listen {
|
||||
|
Loading…
Reference in New Issue
Block a user