3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

Merge remote-tracking branch 'slingmann/recovery'

This commit is contained in:
Daniel Oaks 2017-10-29 04:37:57 +00:00
commit c6b6a25906
5 changed files with 37 additions and 8 deletions

View File

@ -197,6 +197,20 @@ func (client *Client) run() {
var line string var line string
var msg ircmsg.IrcMessage var msg ircmsg.IrcMessage
defer func() {
if r := recover(); r != nil {
client.server.logger.Error("internal",
fmt.Sprintf("Client caused panic: %v\n%s", r, debug.Stack()))
if client.server.RecoverFromErrors() {
client.server.logger.Error("internal", "Disconnecting client and attempting to recover")
} else {
panic(r)
}
}
// ensure client connection gets closed
client.destroy()
}()
client.idletimer = NewIdleTimer(client) client.idletimer = NewIdleTimer(client)
client.idletimer.Start() client.idletimer.Start()
@ -238,9 +252,6 @@ func (client *Client) run() {
break break
} }
} }
// ensure client connection gets closed
client.destroy()
} }
// //

View File

@ -188,7 +188,8 @@ type Config struct {
Logging []logger.LoggingConfig Logging []logger.LoggingConfig
Debug struct { Debug struct {
StackImpact StackImpactConfig RecoverFromErrors *bool `yaml:"recover-from-errors"`
StackImpact StackImpactConfig
} }
Limits struct { Limits struct {

View File

@ -23,6 +23,12 @@ func (server *Server) getPassword() []byte {
return server.password return server.password
} }
func (server *Server) RecoverFromErrors() bool {
server.configurableStateMutex.RLock()
defer server.configurableStateMutex.RUnlock()
return server.recoverFromErrors
}
func (server *Server) ProxyAllowedFrom() []string { func (server *Server) ProxyAllowedFrom() []string {
server.configurableStateMutex.RLock() server.configurableStateMutex.RLock()
defer server.configurableStateMutex.RUnlock() defer server.configurableStateMutex.RUnlock()

View File

@ -109,6 +109,7 @@ type Server struct {
operclasses map[string]OperClass operclasses map[string]OperClass
password []byte password []byte
passwords *passwd.SaltedManager passwords *passwd.SaltedManager
recoverFromErrors bool
registeredChannels map[string]*RegisteredChannel registeredChannels map[string]*RegisteredChannel
registeredChannelsMutex sync.RWMutex registeredChannelsMutex sync.RWMutex
rehashMutex sync.Mutex rehashMutex sync.Mutex
@ -1239,21 +1240,23 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
server.name = config.Server.Name server.name = config.Server.Name
server.nameCasefolded = casefoldedName server.nameCasefolded = casefoldedName
} }
server.networkName = config.Network.Name
server.configurableStateMutex.Lock() server.configurableStateMutex.Lock()
server.networkName = config.Network.Name
if config.Server.Password != "" { if config.Server.Password != "" {
server.password = config.Server.PasswordBytes() server.password = config.Server.PasswordBytes()
} else { } else {
server.password = nil server.password = nil
} }
server.configurableStateMutex.Unlock()
// apply new WebIRC command restrictions // apply new WebIRC command restrictions
server.webirc = config.Server.WebIRC server.webirc = config.Server.WebIRC
// apply new PROXY command restrictions // apply new PROXY command restrictions
server.proxyAllowedFrom = config.Server.ProxyAllowedFrom server.proxyAllowedFrom = config.Server.ProxyAllowedFrom
server.recoverFromErrors = true
if config.Debug.RecoverFromErrors != nil {
server.recoverFromErrors = *config.Debug.RecoverFromErrors
}
server.configurableStateMutex.Unlock()
err = server.connectionLimiter.ApplyConfig(config.Server.ConnectionLimiter) err = server.connectionLimiter.ApplyConfig(config.Server.ConnectionLimiter)
if err != nil { if err != nil {

View File

@ -267,6 +267,14 @@ logging:
# debug options # debug options
debug: debug:
# when enabled, oragono will attempt to recover from certain kinds of
# client-triggered runtime errors that would normally crash the server.
# this makes the server more resilient to DoS, but could result in incorrect
# behavior. deployments that would prefer to "start from scratch", e.g., by
# letting the process crash and auto-restarting it with systemd, can set
# this to false.
recover-from-errors: true
# enabling StackImpact profiling # enabling StackImpact profiling
stackimpact: stackimpact:
# whether to use StackImpact # whether to use StackImpact