Commit c038a45
fix: prevent race in ConcurrentBatch when a batch fails with workers=1
The test TestConcurrentBatchWhenOneBatchFailsAndWorkersIsOne was flaky
because there was a race between the semaphore release and errgroup's
context cancellation. When a batch failed, it would release the
semaphore (via defer) before errgroup cancelled the context, allowing
the next iteration's sem.Acquire to succeed and execute an additional
batch.
Fix this by using an atomic.Bool flag that is set immediately when a
batch returns an error. The main loop checks this flag after acquiring
the semaphore, ensuring no new batches are launched after a failure.
Co-Authored-By: Claude Opus 4.5 <[email protected]>1 parent 85c0916 commit c038a45
1 file changed
+15
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
63 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
64 | 78 | | |
65 | 79 | | |
66 | 80 | | |
| |||
0 commit comments