Add panic recovery to RPC handleConnection (bd-1048)

This commit is contained in:
Steve Yegge
2025-11-02 17:11:51 -08:00
parent fa5fd1bd4e
commit edb9c9e2ab

View File

@@ -10,6 +10,7 @@ import (
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/debug"
"sync/atomic" "sync/atomic"
"time" "time"
) )
@@ -179,6 +180,14 @@ func (s *Server) handleSignals() {
func (s *Server) handleConnection(conn net.Conn) { func (s *Server) handleConnection(conn net.Conn) {
defer func() { _ = conn.Close() }() defer func() { _ = conn.Close() }()
// Recover from panics to prevent daemon crash (bd-1048)
defer func() {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "PANIC in handleConnection: %v\n", r)
fmt.Fprintf(os.Stderr, "Stack trace:\n%s\n", debug.Stack())
}
}()
reader := bufio.NewReader(conn) reader := bufio.NewReader(conn)
writer := bufio.NewWriter(conn) writer := bufio.NewWriter(conn)