3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00
Handle panics in rehash, even if it was triggered by SIGHUP
This commit is contained in:
Shivaram Lingamneni 2021-03-10 23:04:16 -05:00
parent de31430fdc
commit 4e49a25ba6

View File

@ -153,10 +153,8 @@ func (server *Server) Run() {
return
case <-server.rehashSignal:
go func() {
server.logger.Info("server", "Rehashing due to SIGHUP")
server.rehash()
}()
server.logger.Info("server", "Rehashing due to SIGHUP")
go server.rehash()
}
}
}
@ -520,14 +518,24 @@ func (client *Client) getWhoisOf(target *Client, hasPrivs bool, rb *ResponseBuff
// rehash reloads the config and applies the changes from the config file.
func (server *Server) rehash() error {
// #1570; this needs its own panic handling because it can be invoked via SIGHUP
defer func() {
if r := recover(); r != nil {
if server.Config().Debug.recoverFromErrors {
server.logger.Error("internal",
fmt.Sprintf("Panic during rehash: %v\n%s", r, debug.Stack()))
} else {
panic(r)
}
}
}()
server.logger.Info("server", "Attempting rehash")
// only let one REHASH go on at a time
server.rehashMutex.Lock()
defer server.rehashMutex.Unlock()
server.logger.Debug("server", "Got rehash lock")
config, err := LoadConfig(server.configFilename)
if err != nil {
server.logger.Error("server", "failed to load config file", err.Error())