3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

make error recovery configurable

This commit is contained in:
Shivaram Lingamneni 2017-10-26 04:19:01 -04:00
parent 80968d000f
commit 7b58bf76ef
5 changed files with 28 additions and 8 deletions

View File

@ -185,9 +185,11 @@ func (client *Client) run() {
var msg ircmsg.IrcMessage var msg ircmsg.IrcMessage
defer func() { defer func() {
if r := recover(); r != nil { if client.server.RecoverFromErrors() {
client.server.logger.Error("internal", if r := recover(); r != nil {
fmt.Sprintf("Client caused panic, disconnecting: %v\n%s", r, debug.Stack())) client.server.logger.Error("internal",
fmt.Sprintf("Client caused panic, disconnecting: %v\n%s", r, debug.Stack()))
}
} }
// ensure client connection gets closed // ensure client connection gets closed
client.destroy() 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
@ -1250,21 +1251,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