mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-26 13:59:44 +01:00
server: Add a mutex to kill a very small, bad race
This commit is contained in:
parent
835187a736
commit
1812edb2db
@ -59,32 +59,33 @@ type ListenerEvent struct {
|
|||||||
|
|
||||||
// Server is the main Oragono server.
|
// Server is the main Oragono server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
accounts map[string]*ClientAccount
|
accounts map[string]*ClientAccount
|
||||||
channels ChannelNameMap
|
channels ChannelNameMap
|
||||||
clients *ClientLookupSet
|
clients *ClientLookupSet
|
||||||
commands chan Command
|
commands chan Command
|
||||||
configFilename string
|
configFilename string
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
store buntdb.DB
|
store buntdb.DB
|
||||||
idle chan *Client
|
idle chan *Client
|
||||||
limits Limits
|
limits Limits
|
||||||
listenerUpdateMutex sync.Mutex
|
listenerEventActMutex sync.Mutex
|
||||||
listeners map[string]ListenerInterface
|
listenerUpdateMutex sync.Mutex
|
||||||
monitoring map[string][]Client
|
listeners map[string]ListenerInterface
|
||||||
motdLines []string
|
monitoring map[string][]Client
|
||||||
name string
|
motdLines []string
|
||||||
nameCasefolded string
|
name string
|
||||||
networkName string
|
nameCasefolded string
|
||||||
newConns chan clientConn
|
networkName string
|
||||||
operators map[string][]byte
|
newConns chan clientConn
|
||||||
password []byte
|
operators map[string][]byte
|
||||||
passwords *PasswordManager
|
password []byte
|
||||||
rehashMutex sync.Mutex
|
passwords *PasswordManager
|
||||||
accountRegistration *AccountRegistration
|
rehashMutex sync.Mutex
|
||||||
signals chan os.Signal
|
accountRegistration *AccountRegistration
|
||||||
whoWas *WhoWasList
|
signals chan os.Signal
|
||||||
isupport *ISupportList
|
whoWas *WhoWasList
|
||||||
checkIdent bool
|
isupport *ISupportList
|
||||||
|
checkIdent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -341,6 +342,11 @@ func (s *Server) createListener(addr string, tlsMap map[string]*tls.Config) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case event := <-s.listeners[addr].Events:
|
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 {
|
if event.Type == DestroyListener {
|
||||||
// listener should already be closed, this is just for safety
|
// listener should already be closed, this is just for safety
|
||||||
listener.Close()
|
listener.Close()
|
||||||
@ -922,6 +928,7 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server.listenerEventActMutex.Lock()
|
||||||
if exists {
|
if exists {
|
||||||
// update old listener
|
// update old listener
|
||||||
fmt.Println("refreshing", addr)
|
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
|
// force listener to apply the event right away
|
||||||
server.listeners[addr].Listener.Close()
|
server.listeners[addr].Listener.Close()
|
||||||
|
|
||||||
|
server.listenerEventActMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, newaddr := range config.Server.Listen {
|
for _, newaddr := range config.Server.Listen {
|
||||||
|
Loading…
Reference in New Issue
Block a user