From 39780b6fe49336954ee306ddbb205225675c6231 Mon Sep 17 00:00:00 2001 From: harry890829 Date: Mon, 2 Nov 2020 15:53:21 +0800 Subject: [PATCH] when I receive notify of onDownloadStart/onDownloadPause..., then I use gid to deal aria2TellStatus to get status, the deadlock happen. use goroutine to deal it. --- rpc/call.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/rpc/call.go b/rpc/call.go index 11cb137..fc3c822 100644 --- a/rpc/call.go +++ b/rpc/call.go @@ -177,22 +177,24 @@ func newWebsocketCaller(ctx context.Context, uri string, timeout time.Duration, } if resp.Id == nil { // RPC notifications if notifier != nil { - switch resp.Method { - case "aria2.onDownloadStart": - notifier.OnDownloadStart(resp.Params) - case "aria2.onDownloadPause": - notifier.OnDownloadPause(resp.Params) - case "aria2.onDownloadStop": - notifier.OnDownloadStop(resp.Params) - case "aria2.onDownloadComplete": - notifier.OnDownloadComplete(resp.Params) - case "aria2.onDownloadError": - notifier.OnDownloadError(resp.Params) - case "aria2.onBtDownloadComplete": - notifier.OnBtDownloadComplete(resp.Params) - default: - log.Printf("unexpected notification: %s", resp.Method) - } + go func() { + switch resp.Method { + case "aria2.onDownloadStart": + notifier.OnDownloadStart(resp.Params) + case "aria2.onDownloadPause": + notifier.OnDownloadPause(resp.Params) + case "aria2.onDownloadStop": + notifier.OnDownloadStop(resp.Params) + case "aria2.onDownloadComplete": + notifier.OnDownloadComplete(resp.Params) + case "aria2.onDownloadError": + notifier.OnDownloadError(resp.Params) + case "aria2.onBtDownloadComplete": + notifier.OnBtDownloadComplete(resp.Params) + default: + log.Printf("unexpected notification: %s", resp.Method) + } + }() } continue }