Repository navigation
fix(npm): stop the server when start() misses the startup deadline - #1515
Conversation
start() registered its exit hook only after the server became healthy. When the health wait failed, the extenddb serve process that start() spawned kept running. A caller that exited during the health wait also left it running. packaging/README.md says that a launcher does not outlive the caller. start() now adds the exit hook right after the spawn. When the health wait fails, start() kills the server and waits for its exit before it rejects. The hook goes away when the server exits, so stop() no longer leaves one exit listener behind for each start. Before, the eleventh start in one process printed MaxListenersExceededWarning. Test scenario 10 checks that the fake server is gone after the rejection, in place of stopping it by hand. Scenarios 9 and 10 check that start() leaves no exit listener behind. Fixes #1163 Refs #924 Signed-off-by: Elise Ong <eliseong@amazon.com>
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Thanks. I read the change against main 92155f3. The launcher suite passed all 11 scenarios in 3 of 3 runs at this head and on main. Each tree ran with its own dev-mode binary. This PR's test file fails against main's index.js at line 510 (10 !== 6 exit listeners). With that line removed, it fails at line 539, because the fake server outlived the failed start. So both new assertions catch the defects.
The fix does what the description says. The launcher registers the exit hook right after the spawn. A start that misses the deadline kills the server and waits for its exit before it rejects. A healthy start removes the hook when the server exits. The ESRCH check in scenario 10 cannot race, because Node reaps the child before it emits exit.
The three red checks do not come from this change. Each run built its merge commit with main at 5252eda. That base has two breaks that main has fixed since: the secmem test failure (#1522 removed that test) and the wasm type errors (#1482). A re-run builds the same merge commit, so please merge main into the branch. I will approve when the checks pass on it.
#741 (opened 2 November) makes the same failed-start stop in the same lines, with the same change to scenario 10. Its commit b0d5906 wraps the health wait in try and catch, and calls stopChild(child) before it throws again. #1162 (opened 19 November) changes the same .catch for a detached server. The description names #1162 but not #741. This PR and #741 differ in two places:
- The signal. #741 sends SIGTERM, then SIGKILL after 5 s. This PR sends SIGKILL at once, as the caller-exit path on main does.
- The hook. #741 registers the exit hook after the health wait and never removes it, so item 2 of #924 stays open there. The hook placement and its removal are this PR's own.
The second of the two to merge should leave one stop helper for stop() and the failed start, and keep this PR's hook placement and removal. The signal then follows the helper. Please name #741 in the description.
packaging/npm/README.md (lines 55-57) and the start() doc comment do not say that a rejected start() stops the server that it spawned. One sentence in each would say it.
…rtup-timeout-2026-11-25
Signed-off-by: Elise Ong <eliseong@amazon.com>
LeeroyHannigan
left a comment
There was a problem hiding this comment.
Approve. You merged main, and the checks passed on the new merge. The fix commit, 88bd4a4, is the one I reviewed in round 1. The merge commit is a clean merge of main at ac0c581: its tree is the one git merge-tree builds from the two parents.
The new commit adds the two sentences I asked for. packaging/npm/README.md and the startupTimeoutMs doc comment now say that a start() that misses the deadline stops the server it spawned before it rejects.
CI passed at this head, 69 of 69.
This still makes the same failed-start stop as #741 (opened 2 November), in the same lines of packaging/npm/index.js. #1162 (opened 19 November) changes the same .catch. As round 1 said, the second of these to merge should leave one stop helper and keep this PR's hook placement and removal. The description names #1162 but not #741 yet, and naming it would help whoever merges second.
Main is at c8e66fb, six commits past 01556cf: #481, #1137, #1403, #1465, #1515 and #1411. #1403 and #1411 add v1.2.0 entries at the top of "Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md, where the entry of this branch goes next. The merge has no conflict. Git merged crates/core/src/types/table.rs and crates/engine/src/lib.rs at other lines. In table.rs, main changes the members of a DELETING table in TableDescription, and this branch adds the ReplicaUpdates member of UpdateTableInput. In lib.rs, main declares a test module, and this branch declares nested_enums and adds enum_constraint. The lines that this branch changes are the same before and after the merge.
The base merges main at c8e66fb, which brings #481, #1137, #1403, #1465, #1515 and #1411, and adds the v1.2.0 entries of #1110 and #1114 to docs/manuals/07-upgrade-manual.md. The merge has no conflict. Git merged two files at other lines. In crates/core/src/types/table.rs, main changes the members of a DELETING table in TableDescription, and this branch changes the doc comment of the SSESpecification member of UpdateTableInput. In crates/storage-mongodb/src/table_engine.rs, main makes the creation time of a table description optional, and this branch records the specification in update_table.
Main is at c8e66fb, three commits past e8b5f10: #1465, #1515 and #1411. #1411 adds a v1.2.0 entry at the top of "Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md, above the entry of #606. Git merged the file with no conflict, so the order is #1411, #606, then the entry of this branch. No other file has changes on both sides.
The base brings main at c8e66fb through #1260, with #1465, #1515 and #1411, and adds the v1.2.0 entry of #1313 to docs/manuals/07-upgrade-manual.md. Git merged the manual with no conflict. The order of the v1.2.0 entries is #1313, #1411, #606, #1260, then the entry of this branch. No other file has changes on both sides.
What
start()in@extenddb/devnow stops the server it spawned when the server does not become healthy withinstartupTimeoutMs. It kills the server and waits for its exit before it rejects.start()added it only after the health wait succeeded, so a caller that exited during the health wait also left the server running.start()left one exit listener behind afterstop(), and the eleventh start in one process printedMaxListenersExceededWarning.packaging/npm/README.mdand thestartupTimeoutMsdoc comment ofstart()now say that a start that misses the deadline stops the server before it rejects.Why
Closes #1163
This is also items 1 and 2 of #924. Items 3 and 4 of #924 (a relative
binarypath, and the double retry of a timed-out probe) are not changed here.packaging/README.md says that a launcher does not outlive the caller.
Testing done
EXTENDDB_BINARY=<dev-mode build of this branch> node test/launcher.test.jsinpackaging/npm: 11 scenarios passed, twice, with no warnings.start()leaves no exit listener behind.index.jsfails: scenario 9 counts 10 exit listeners where 6 were present before its starts. With that check removed, scenario 10 fails at the check that the fake server is gone.servelistens 5 s after it starts, withstartupTimeoutMs: 2000. On main theserveprocess is still running after the rejection and after the caller exits. On this branch it is gone at the rejection. Run twice on each.process.exit()1.5 s into a 5 s health wait. On main theserveprocess keeps running. On this branch it is gone. Run twice on each.start()andstop()cycles in one process with the real binary: 12 exit listeners remain on main and 0 on this branch.stop(): the server stops, as before.Notes
stop()and the failed start, and keeps this PR's exit hook placement and removal..catchon the health wait and removes the exit hook for a detached server beforechild.unref().Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.