Commit 615530b
authored
fix(core): remove race condition in shutdown state transition (#1088)
## Summary
- Fix a race condition in `GracefulShutdownManager` where the monitor
thread (with `initialDelay=0`) calls `updateTerminatedIfNoRequests()` on
every tick, which can advance the state from `SHUTTING_DOWN` to
`TERMINATED` before `performGracefulShutdown()` even returns. This
causes `performShutdownTransition` test to fail flakily.
- Move `updateTerminatedIfNoRequests()` from the monitor thread to two
deterministic call sites: `unregisterRequest()` (when the last request
completes) and `awaitTermination()` entry (for the "no active requests
at shutdown time" edge case).
## Root Cause
The monitor thread was responsible for both timeout enforcement (its
intended job) and state transition (an overreach). Since it runs with
`initialDelay=0`, it could execute `updateTerminatedIfNoRequests()`
before `performGracefulShutdown()` returned to the caller, making the
`SHUTTING_DOWN` state unobservable.
## Test plan
- [x] `GracefulShutdownTest` (59 tests) all pass, including the
previously flaky `performShutdownTransition`
- [x] No other files changed, minimal blast radius
Made with [Cursor](https://cursor.com)1 parent 1fda297 commit 615530b
1 file changed
Lines changed: 2 additions & 3 deletions
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| |||
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | 266 | | |
269 | 267 | | |
270 | 268 | | |
| |||
284 | 282 | | |
285 | 283 | | |
286 | 284 | | |
| 285 | + | |
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
| |||
0 commit comments