Commit 20e0cd1
committed
Fix flaky TestConn_ExecContext: don't cancel a finished operation
The sentinel Watch loop had a race: once StatusFn reported Done, it
spawned the OnDoneFn processor and looped back into its select with two
potentially-ready cases at once -- the processor result (resCh) and
ctx.Done(). Go's select picks randomly among ready cases, so a context
cancellation arriving at the same instant as completion could win and
trigger OnCancelFn, cancelling an operation that had already finished.
TestConn_ExecContext/"ExecContext uses new context to close operation"
cancels the context inside GetOperationStatus while returning FINISHED,
then asserted cancelOperationCount == 1 -- i.e. it asserted on the losing
side of that random select. The Go scheduler version only shifts the
probability; the race is in the design, not the language version.
Fix: once Done is observed, the operation has logically completed and its
outcome is authoritative. Drain the OnDoneFn result via a new waitForDone
helper that selects only on resCh/errCh, no longer on ctx.Done()/timeout.
A finished operation is now never cancelled, deterministically.
Update the connection test to assert the correct deterministic behaviour
(success, cancelOperationCount == 0, CloseOperation still runs on a fresh
context) and add a sentinel regression test that pre-cancels the context
in the same StatusFn call that reports Done, looped 1000x.
Verified: TestConn_ExecContext -count=300 green; sentinel suite green
under -race -count=5.
Co-authored-by: Isaac1 parent c3be94a commit 20e0cd1
3 files changed
Lines changed: 71 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1576 | 1576 | | |
1577 | 1577 | | |
1578 | 1578 | | |
1579 | | - | |
1580 | | - | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
1581 | 1587 | | |
1582 | | - | |
| 1588 | + | |
1583 | 1589 | | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
1584 | 1593 | | |
1585 | 1594 | | |
1586 | 1595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
117 | 123 | | |
118 | | - | |
119 | | - | |
| 124 | + | |
120 | 125 | | |
| 126 | + | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
| |||
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
260 | 298 | | |
261 | 299 | | |
262 | 300 | | |
| |||
0 commit comments