From 7ddc7ed644bedc36c98042f56d0399911c9cdabd Mon Sep 17 00:00:00 2001 From: Sebastien Melki Date: Wed, 16 Oct 2019 10:08:24 +0300 Subject: [PATCH] =?UTF-8?q?When=20queue=20is=20full,=20requests=20hang=20b?= =?UTF-8?q?ecause=20Wait.Done()=20is=20not=20cal=E2=80=A6=20(#430)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * if queue is full then mark notification as failed and unblock the wait group instead of hanging * use WaitDone() function instead of calling Done() on notification wait group as it is safer --- gorush/worker.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gorush/worker.go b/gorush/worker.go index a99c657..9b665ba 100644 --- a/gorush/worker.go +++ b/gorush/worker.go @@ -1,6 +1,7 @@ package gorush import ( + "errors" "sync" ) @@ -30,6 +31,15 @@ func startWorker() { } } +// markFailedNotification adds failure logs for all tokens in push notification +func markFailedNotification(notification *PushNotification, reason string) { + LogError.Error(reason) + for _, token := range notification.Tokens { + notification.AddLog(getLogPushEntry(FailedPush, token, *notification, errors.New(reason))) + } + notification.WaitDone() +} + // queueNotification add notification to queue list. func queueNotification(req RequestPush) (int, []LogPushEntry) { var count int @@ -58,7 +68,7 @@ func queueNotification(req RequestPush) (int, []LogPushEntry) { notification.AddWaitCount() } if !tryEnqueue(*notification, QueueNotification) { - LogError.Error("max capacity reached") + markFailedNotification(notification, "max capacity reached") } count += len(notification.Tokens) // Count topic message