@@ -270,14 +270,14 @@ func (s *RequestLogService) flush() {
270270 }
271271
272272 if len (logs ) == 0 {
273- // Delete corrupted keys only if deletion succeeds, then decrement counter
273+ // Decrement pendingCount regardless of Del success since keys are already popped from set
274+ // This prevents counter drift when Del fails but keys are already removed from tracking set
274275 if len (badKeys ) > 0 {
275276 if err := s .store .Del (badKeys ... ); err != nil {
276277 logrus .WithError (err ).Error ("Failed to delete corrupted log bodies from store" )
277- } else {
278- // Only decrement counter after successful deletion to maintain accuracy
279- atomic .AddInt64 (& s .pendingCount , - int64 (len (badKeys )))
280278 }
279+ // Decrement regardless of Del success since keys are already popped from set
280+ atomic .AddInt64 (& s .pendingCount , - int64 (len (badKeys )))
281281 }
282282 if len (retryKeys ) > 0 {
283283 args := make ([]any , len (retryKeys ))
@@ -311,14 +311,14 @@ func (s *RequestLogService) flush() {
311311 logrus .Errorf ("CRITICAL: Failed to re-add failed log keys to set: %v" , saddErr )
312312 }
313313 }
314- // Delete corrupted keys only if deletion succeeds, then decrement counter
314+ // Decrement pendingCount regardless of Del success since keys are already popped from set
315+ // This prevents counter drift when Del fails but keys are already removed from tracking set
315316 if len (badKeys ) > 0 {
316317 if delErr := s .store .Del (badKeys ... ); delErr != nil {
317318 logrus .WithError (delErr ).Error ("Failed to delete corrupted log bodies from store" )
318- } else {
319- // Only decrement counter after successful deletion to maintain accuracy
320- atomic .AddInt64 (& s .pendingCount , - int64 (len (badKeys )))
321319 }
320+ // Decrement regardless of Del success since keys are already popped from set
321+ atomic .AddInt64 (& s .pendingCount , - int64 (len (badKeys )))
322322 }
323323 // Decrement pendingCount for missing keys to prevent counter drift
324324 if missingCount > 0 {
0 commit comments