fix(daemon): add panic recovery (#1306)
Mohamed Mahmoud
created 1 month ago
## What?
Added panic recovery to the async refresh goroutine in
`daemon/handler.go`.
## Why?
The goroutine had no panic recovery. A panic from any provider would
crash the entire daemon. Now it recovers and notifies subscribers
instead.
Closes #1121
Change summary
daemon/handler.go | 11 +++++++++++
1 file changed, 11 insertions(+)
Detailed changes
@@ -310,6 +310,17 @@ func (d *Daemon) handleRefreshFolder(conn *daemonrpc.Conn, req *daemonrpc.Reques
// Async: fetch in background, push events when done.
go func() {
+ defer func() {
+ if r := recover(); r != nil {
+ log.Printf("daemon: refresh panic for account = %s folder = %s: %v", params.AccountID, params.Folder, r)
+ d.broadcastToSubscribers(params.AccountID, params.Folder, daemonrpc.EventSyncError, daemonrpc.SyncErrorEvent{
+ AccountID: params.AccountID,
+ Folder: params.Folder,
+ Error: fmt.Sprintf("panic: %v", r),
+ })
+ }
+ }()
+
p, err := d.getProvider(params.AccountID)
if err != nil {
log.Printf("daemon: refresh provider error: %v", err)