Commit 39b4e48
authored
fix(daemon): reject instead of hanging when the socket claim loses the race (#108)
**Stacked on #107.** A regression this stack introduced, caught by a
verification pass over the earlier fixes.
`gatewayStarted` is settled only from inside `onSocketClaimed`'s
handler, and `DaemonServer.start()` fires that callback only once the
socket claim **and** the admin-secret write have succeeded. So a daemon
that loses the start race rejects with `DaemonAlreadyRunningError`
without the callback ever running — nothing settles `gatewayStarted`,
and the `Promise.allSettled` join added by the bind-failure fix waits on
it **forever**.
`startDaemon()` therefore hung: no rejection, no "Daemon failed to
start", no non-zero exit code. Both `main` and the pre-fix stack awaited
`daemon.start()` alone and rejected immediately, so this is a regression
introduced by that fix, not a pre-existing gap. It is reachable by
racing `simlock daemon start`, and by the CLI's own auto-launch — a
common path, not an exotic one, whenever HTTP is enabled.
The fix releases `gatewayStarted` on the `daemon.start()` failure path.
A `socketClaimed` guard keeps it from resolving early while a *claimed*
daemon's gateway is still binding, so a genuine bind failure is still
reported — the behaviour the previous PR added stays intact.
The regression test races two `startDaemon()` calls on one data
directory with distinct HTTP ports, so the only thing that can fail is
the socket claim, and asserts the second **rejects** rather than
hanging. Verified by stashing the fix: without it the test reports
`hung` instead of `rejected`.1 parent a9f6aac commit 39b4e48
2 files changed
Lines changed: 67 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
| 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 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
327 | 379 | | |
328 | 380 | | |
329 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
| |||
263 | 266 | | |
264 | 267 | | |
265 | 268 | | |
| 269 | + | |
266 | 270 | | |
267 | 271 | | |
268 | 272 | | |
| |||
309 | 313 | | |
310 | 314 | | |
311 | 315 | | |
312 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
313 | 327 | | |
314 | 328 | | |
315 | 329 | | |
| |||
0 commit comments