Commit bdb8f71
committed
fix(telemetry): drain remaining BBolt writers before shutdown-marker resolve (Spec 080, review round 4)
Two writers could still hit BBolt after Close() resolved the clean-shutdown
marker (FR-010: the marker resolve must be the final DB write of a graceful
shutdown) or even after the DB handle closed:
1. Error-code notifier (runtime.go SetTelemetry wiring): review round 1 made
the notifier synchronous for FR-012 but kept the 24h diagnostics counter
write in an untracked goroutine — no better tracked than the pre-branch
`go notifier(code)` in the supervisor, and now able to race the marker
resolve. The counter write is now synchronous too: it completes inside the
supervisor's call stack, so Supervisor.Stop() (which joins its goroutines
before Close touches storage) is a hard barrier. Safe: sub-ms BBolt
Update, the callback never re-enters the supervisor (documented at
notifyErrorCode), and RecordLastErrorCode already writes synchronously
under identical locking. SetErrorCodeNotifier's contract now forbids
callback goroutines that outlive the call. The untracked-goroutine
exposure itself pre-dates the branch; the marker invariant it violates is
new here, and the specific goroutine was introduced in round 1 (1ec8109).
2. ActivityService (activity records, retention pruning, usage-snapshot
flushes, async sensitive-data detection — all BBolt writes): Close() only
context-cancelled it and never awaited it, so the flush-on-shutdown
(persistUsage) and any in-flight worker could land after the marker
resolve or be lost at DB close. Pre-existing on main (Stop() existed but
was never called from Close); the Spec 080 marker invariant makes it
observable, so it is fixed on this branch. ActivityService.Stop() is now
idempotent, returns immediately if Start never ran, and waits for the
event loop's final flush plus a WaitGroup over the retention loop, the
usage-flush loop, and per-event detection goroutines. Close() calls it
after appCancel (so the final flush is captured) and BEFORE
StopAsync/ResolveCleanShutdown/storage Close.
Tests: TestRuntimeCloseWaitsForActivityWritersBeforeMarkerResolve proves the
shutdown flush lands before the DB closes AND the marker still resolves to
clean; TestActivityServiceStopSafeWhenNeverStartedAndIdempotent covers the
never-started and repeated-Stop paths (every existing prechurn test now
exercises the never-started branch through Close).1 parent 6a334d2 commit bdb8f71
4 files changed
Lines changed: 200 additions & 15 deletions
File tree
- internal/runtime
- supervisor
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
44 | 55 | | |
45 | 56 | | |
46 | 57 | | |
| |||
116 | 127 | | |
117 | 128 | | |
118 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
119 | 141 | | |
120 | 142 | | |
121 | 143 | | |
122 | 144 | | |
123 | | - | |
124 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
125 | 152 | | |
126 | 153 | | |
127 | | - | |
| 154 | + | |
128 | 155 | | |
129 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
130 | 161 | | |
131 | 162 | | |
132 | 163 | | |
| |||
213 | 244 | | |
214 | 245 | | |
215 | 246 | | |
216 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
217 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
218 | 269 | | |
| 270 | + | |
219 | 271 | | |
220 | 272 | | |
221 | 273 | | |
| |||
355 | 407 | | |
356 | 408 | | |
357 | 409 | | |
358 | | - | |
| 410 | + | |
| 411 | + | |
359 | 412 | | |
360 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
361 | 418 | | |
362 | 419 | | |
363 | 420 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
142 | 244 | | |
143 | 245 | | |
144 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
656 | 670 | | |
657 | 671 | | |
658 | 672 | | |
| |||
2524 | 2538 | | |
2525 | 2539 | | |
2526 | 2540 | | |
2527 | | - | |
2528 | | - | |
2529 | | - | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
2530 | 2553 | | |
2531 | 2554 | | |
2532 | 2555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
813 | | - | |
814 | | - | |
815 | | - | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
816 | 819 | | |
817 | 820 | | |
818 | 821 | | |
| |||
0 commit comments