Add panic handlers for user and downstream goroutines

This only brings down a single user or downstream on panic, instead
or bringing down the whole bouncer.

Closes: https://todo.sr.ht/~emersion/soju/139
This commit is contained in:
Simon Ser 2021-11-15 21:40:17 +01:00
parent 37c1b3e29c
commit b9e06e498e

View File

@ -9,6 +9,7 @@ import (
"mime"
"net"
"net/http"
"runtime/debug"
"sync"
"sync/atomic"
"time"
@ -163,6 +164,12 @@ func (s *Server) addUserLocked(user *User) *user {
s.stopWG.Add(1)
go func() {
defer func() {
if err := recover(); err != nil {
s.Logger.Printf("panic serving user %q: %v\n%v", user.Username, err, debug.Stack())
}
}()
u.run()
s.lock.Lock()
@ -178,6 +185,12 @@ func (s *Server) addUserLocked(user *User) *user {
var lastDownstreamID uint64 = 0
func (s *Server) handle(ic ircConn) {
defer func() {
if err := recover(); err != nil {
s.Logger.Printf("panic serving downstream %q: %v\n%v", ic.RemoteAddr(), err, debug.Stack())
}
}()
atomic.AddInt64(&s.connCount, 1)
id := atomic.AddUint64(&lastDownstreamID, 1)
dc := newDownstreamConn(s, ic, id)