Commit 83dfcad
authored
feat: Add time.Sleep to mitigate race condition. (#1923)
The ShuffleQueue scheduler strategy has an infrequent race condition, as
explained by the comment:
```
// A race condition is possible when the last active table asynchronously
// queues a relation. The table finishes (calling `.Done()`) a moment
// before the queue receives the `.Push()`. At this point, the queue is
// empty and there are no active workers.
//
// A moment later, the queue receives the `.Push()` and queues a new task.
//
// This is a very infrequent case according to tests, but it happens.
```
After many attempts at a more elegant solution, I finally yielded:
```
time.Sleep(10 * time.Millisecond)
```
Looks ugly, but after running the tests 300 times (so around 3000
syncs), it works 🤷
```
✓ cloudquery/plugin-sdk main* $ go test ./scheduler -count=100 -run TestScheduler ⏱ 15:04:12
ok github.com/cloudquery/plugin-sdk/v4/scheduler 143.523s
✓ cloudquery/plugin-sdk main* $ go test ./scheduler -count=100 -run TestScheduler ⏱ 15:06:56
ok github.com/cloudquery/plugin-sdk/v4/scheduler 142.796s
✓ cloudquery/plugin-sdk main* $ go test ./scheduler -count=100 -run TestScheduler ⏱ 15:09:22
ok github.com/cloudquery/plugin-sdk/v4/scheduler 144.304s
```1 parent d51e172 commit 83dfcad
1 file changed
+11
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
| |||
0 commit comments