Repository navigation
Commit 39bbfb4
committed
fix: close races between HashedWheelTimer stop() and concurrent register-ers
stop() previously did a plain `if (stopped) return; stopped = true` then snapshot+clear of
stopHooks. Three races followed:
- Double stop() ran every hook twice (both callers passed the early check before either
wrote the flag).
- onStop() racing with stop() could land an add after the snapshot/clear, leaving the hook
stranded in the set with no worker alive to drive it — the caller's Registration claimed
the hook would fire on stop but it never would.
- newTimeout() racing with stop() left entries in pendingTimeouts that nobody drained.
Switch to AtomicBoolean.compareAndSet for the stop transition. After the CAS, drain
stopHooks AND pendingTimeouts in a loop until both observe empty, so any add that started
before the CAS but landed after the first drain pass gets caught on the next pass.
onStop now invokes the hook synchronously when stop() already happened (ListenableFuture
addListener semantics). newTimeout returns a pre-cancelled singleton in the same case so
callers see `isCancelled() == true` and skip cleanup paths. The register-then-recheck
pattern in each handles the stop()-just-CAS'd-but-not-yet-drained window: the late add
either lands in the queue/set (where stop()'s drain loop catches it) or sees the flag and
self-removes/self-fires.
Drops Scheduled.onStart's try/catch around the timer calls — neither onStop nor newTimeout
can throw on the stopped path anymore.1 parent 8bd9885 commit 39bbfb4
3 files changed
Lines changed: 112 additions & 47 deletions
File tree
- java-bigtable/google-cloud-bigtable/src
- main/java/com/google/cloud/bigtable/data/v2/internal
- middleware
- session
- test/java/com/google/cloud/bigtable/data/v2/internal/session
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
354 | 344 | | |
355 | 345 | | |
356 | 346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
56 | 72 | | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
60 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
61 | 80 | | |
62 | 81 | | |
63 | 82 | | |
| |||
75 | 94 | | |
76 | 95 | | |
77 | 96 | | |
78 | | - | |
79 | | - | |
| 97 | + | |
| 98 | + | |
80 | 99 | | |
81 | 100 | | |
82 | 101 | | |
83 | 102 | | |
84 | 103 | | |
| 104 | + | |
85 | 105 | | |
86 | 106 | | |
87 | 107 | | |
88 | 108 | | |
89 | 109 | | |
90 | | - | |
91 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
92 | 113 | | |
93 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
94 | 124 | | |
95 | 125 | | |
96 | 126 | | |
| 127 | + | |
| 128 | + | |
97 | 129 | | |
98 | 130 | | |
99 | | - | |
| 131 | + | |
100 | 132 | | |
101 | 133 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
110 | 156 | | |
111 | 157 | | |
112 | 158 | | |
113 | 159 | | |
114 | 160 | | |
115 | 161 | | |
116 | 162 | | |
117 | | - | |
| 163 | + | |
118 | 164 | | |
119 | 165 | | |
120 | 166 | | |
| |||
133 | 179 | | |
134 | 180 | | |
135 | 181 | | |
136 | | - | |
| 182 | + | |
137 | 183 | | |
138 | 184 | | |
139 | 185 | | |
140 | 186 | | |
141 | 187 | | |
142 | 188 | | |
143 | | - | |
| 189 | + | |
144 | 190 | | |
145 | 191 | | |
146 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | | - | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| |||
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
86 | | - | |
87 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
88 | 117 | | |
89 | 118 | | |
90 | 119 | | |
| |||
0 commit comments