Commit fda7bef
authored
fix(shared): make SetOnce.WaitWithContext deterministic once value is set (#3241)
When both the Done channel and ctx.Done() are ready, select picks a case
at random, so a wait entered with an already cancelled context could
report ctx.Err() for work that had already completed, randomly turning
finished work into a spurious failure under deadline pressure.
Check the Done channel first and document the contract: a set result
always wins; ctx.Err() is returned only when the context becomes done
before the result is set. This is deliberate -- the context bounds the
waiting, not the delivery of an already-existing result, and fail-fast
callers can still check ctx.Err() themselves.
Drop the stale caller-migration TODO (from #257): the choice between
Wait and WaitWithContext is purely about cancellation, and blocking Wait
remains correct on teardown paths where cancellation must not skip work.1 parent fcf92fa commit fda7bef
2 files changed
Lines changed: 32 additions & 1 deletion
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
105 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
106 | 119 | | |
107 | 120 | | |
108 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
114 | 132 | | |
115 | 133 | | |
116 | 134 | | |
| |||
0 commit comments