When queue is full, requests hang because Wait.Done() is not cal… (#430)
* 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
This commit is contained in:
		
							parent
							
								
									42d406b85f
								
							
						
					
					
						commit
						7ddc7ed644
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue