Commit 09d1705
committed
Fix race condition in InMemoryQueue causing RunUntilEmptyAsync to exit prematurely
During AbandonAsync, there is a window between removing an entry from
_dequeued and re-enqueueing it for retry where the item exists in
neither collection. If RunUntilEmptyAsync checks queue stats during
this gap, it sees Queued=0 + Working=0 and terminates the job loop
while retryable items are still in flight.
Add a _pendingRetryCount that bridges the gap: incremented before
TryRemove, decremented after the item lands in its destination
(re-queued, deadlettered, or scheduled for delayed retry). The count
is included in the Queued stat so the continuation callback sees
items in transit.
For delayed retries (RetryDelay > 0), the counter is decremented
immediately after scheduling since the item is intentionally parked
and RunUntilEmptyAsync should not spin-wait for it.
Fixes flaky CanRunQueueJobWithLockFailAsync test.
Made-with: Cursor1 parent 6c6608c commit 09d1705
1 file changed
+11
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| 296 | + | |
| 297 | + | |
295 | 298 | | |
296 | 299 | | |
| 300 | + | |
| 301 | + | |
297 | 302 | | |
298 | 303 | | |
299 | 304 | | |
| |||
323 | 328 | | |
324 | 329 | | |
325 | 330 | | |
| 331 | + | |
326 | 332 | | |
327 | | - | |
| 333 | + | |
328 | 334 | | |
329 | 335 | | |
330 | 336 | | |
| |||
334 | 340 | | |
335 | 341 | | |
336 | 342 | | |
| 343 | + | |
337 | 344 | | |
338 | 345 | | |
339 | 346 | | |
340 | 347 | | |
341 | 348 | | |
342 | 349 | | |
| 350 | + | |
343 | 351 | | |
344 | 352 | | |
345 | 353 | | |
| |||
373 | 381 | | |
374 | 382 | | |
375 | 383 | | |
| 384 | + | |
376 | 385 | | |
377 | 386 | | |
378 | 387 | | |
| |||
0 commit comments