Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When queue is full, requests hang because Wait.Done() is not called on the affected notification #430

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion gorush/worker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gorush

import (
"errors"
"sync"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down