From 12b69fb718f88d6c1f085fcf58768ac928995e19 Mon Sep 17 00:00:00 2001 From: Benson Wong Date: Mon, 3 Nov 2025 08:30:09 -0500 Subject: [PATCH] proxy: recover from panic in Process.statusUpdate (#378) Process.statusUpdate() panics when it can not write data, usually from a client disconnect. Since it runs in a goroutine and did not have a recover() the result was a crash. ref: https://github.com/mostlygeek/llama-swap/discussions/326#discussioncomment-14856197 --- proxy/process.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/proxy/process.go b/proxy/process.go index 6406358..91bfbd4 100644 --- a/proxy/process.go +++ b/proxy/process.go @@ -733,6 +733,14 @@ func (s *statusResponseWriter) statusUpdates(ctx context.Context) { s.wg.Add(1) defer s.wg.Done() + // Recover from panics caused by client disconnection + // Note: recover() only works within the same goroutine, so we need it here + defer func() { + if r := recover(); r != nil { + s.process.proxyLogger.Debugf("<%s> statusUpdates recovered from panic (likely client disconnect): %v", s.process.ID, r) + } + }() + defer func() { duration := time.Since(s.start) s.sendLine(fmt.Sprintf("\nDone! (%.2fs)", duration.Seconds()))