Skip to content

fix(npm): stop the server when start() misses the startup deadline - #1515

Merged
eliseong merged 3 commits into
mainfrom
eliseong-launcher-startup-timeout-2026-11-25
Dec 3, 2026
Merged

eliseong merged 3 commits into
mainfrom
eliseong-launcher-startup-timeout-2026-11-25

Conversation

@eliseong

@eliseong eliseong commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

start() in @extenddb/dev now stops the server it spawned when the server does not become healthy within startupTimeoutMs. It kills the server and waits for its exit before it rejects.

  • The exit hook that kills the server when the caller exits is added right after the spawn. Before, start() added it only after the health wait succeeded, so a caller that exited during the health wait also left the server running.
  • The hook is removed when the server exits and when the start fails. Before, each start() left one exit listener behind after stop(), and the eleventh start in one process printed MaxListenersExceededWarning.

packaging/npm/README.md and the startupTimeoutMs doc comment of start() 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 binary path, 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.js in packaging/npm: 11 scenarios passed, twice, with no warnings.
  • Scenario 10 now 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.
  • The new test file against main's index.js fails: 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.
  • A fake binary whose serve listens 5 s after it starts, with startupTimeoutMs: 2000. On main the serve process is still running after the rejection and after the caller exits. On this branch it is gone at the rejection. Run twice on each.
  • A caller that calls process.exit() 1.5 s into a 5 s health wait. On main the serve process keeps running. On this branch it is gone. Run twice on each.
  • Twelve start() and stop() cycles in one process with the real binary: 12 exit listeners remain on main and 0 on this branch.
  • A caller that exits after a successful start without calling stop(): the server stops, as before.
  • Spawn failures (a binary that is gone or not executable at spawn), a server that exits or is killed during startup, and a server that ignores SIGTERM all reject with the original error and leave no process and no listener behind.

Notes

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, 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.

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 LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@eliseong
eliseong added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit b3510a9 Dec 3, 2026
70 checks passed
@eliseong
eliseong deleted the eliseong-launcher-startup-timeout-2026-11-25 branch December 3, 2026 00:19
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
The base merges main at c8e66fb, which brings #481, #1137, #1403,
#1465, #1515 and #1411, and adds the v1.2.0 entry of #1110 to
docs/manuals/07-upgrade-manual.md. The merge has no conflict, and no
file has changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
The base merges main at c8e66fb, which brings #1465, #1515 and #1411.
#1411 adds a v1.2.0 entry to docs/manuals/07-upgrade-manual.md. The
merge has no conflict, and no file has changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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. The merge has no conflict, and no
file has changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
The base brings main at c8e66fb through #1260, with #1465, #1515 and
#1411, and adds the v1.2.0 entries of #1313 and #1355 to
docs/manuals/07-upgrade-manual.md. The merge has no conflict, and no
file has changes on both sides.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] @extenddb/dev: start() leaves the server running when it misses the startup deadline

2 participants