Skip to content

test: add regression coverage for #34158 (server.close() teardown wedge) - #34161

Closed
robobun wants to merge 4 commits into
mainfrom
farm/f7c9dc88/windows-graceful-close-ref-hold
Closed

robobun wants to merge 4 commits into
mainfrom
farm/f7c9dc88/windows-graceful-close-ref-hold

Conversation

@robobun

@robobun robobun commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Regression coverage follow-up for #34158 now that #32488 has merged the fix.

What #32488 fixed

stop_listening()'s TCP arm now holds the server's KeepAlive while pending_requests > 0 || has_active_web_sockets(), and Handler::on_connection_closed re-evaluates deinit_if_we_can() so the deferred release completes for WebSocket connections. The Windows half-close quarantine entry was removed there.

What this PR adds

A two-case subprocess regression test guarding that fix:

  • Bun.serve: graceful stop() with an in-flight async handler must not let the process exit before the request's abort is observed (the POSIX-observable half).
  • node:http: the canonical half-close + client-abort + server.close() scenario must drain (previously wedged forever on Windows).

Plus: removes the now-stale expectations.txt comment block (#32488 removed the quarantine entry but left the descriptive comment above it).

Dropped from an earlier revision of this PR

The H3-only sibling arm of stop_listening() (at mod.rs:1545, reached for Bun.serve({tls, http3: true, http1: false})) still releases the ref unconditionally. Applying the same guard there is correct, but testing it is blocked by an lsquic re-entrancy assertion (lsquic_engine.c:3002: !((engine)->pub.enp_flags & ENPUB_PROC)) that fires on any graceful stop() of an http3-only server with a request in flight. That crash and the H3 guard have been filed separately.


[stamp-90s] gate passed · iteration 12 · 2 files touched

passes on PR (with fix)
Test-only change.

Debug/ASAN (expected pass):
$ bun bd test 'test/regression/issue/34158.test.ts'
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "test/regression/issue/34158.test.ts"
info: syncing channel updates for nightly-2026-05-06-x86_64-unknown-linux-gnu
info: latest update on 2026-05-06 for version 1.97.0-nightly (e95e73209 2026-05-05)
info: component rust-src is up to date
info: checking for self-update (current version: 1.29.0)
bun test v1.4.0 (60a613013)

test/regression/issue/34158.test.ts:
(pass) Bun.serve: graceful stop() keeps the loop alive until in-flight requests drain [1862.32ms]
(pass) node:http: server.close() with a half-closed connection drains without wedging [2565.21ms]

 2 pass
 0 fail
 2 expect() calls
Ran 2 tests across 1 file. [4.63s]
Exit: 0
diff hotspot
test/expectations.txt               |  11 ----
 test/regression/issue/34158.test.ts | 122 ++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 11 deletions(-)

gate history · 9 passed · 1 rejected · iteration 12

evidence per changed file
file                                 reads  edits  tests
test/expectations.txt                    6      4      0
test/regression/issue/34158.test.ts      9     15      0

@robobun

robobun commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 1:54 PM PT - Jul 17th, 2026

❌ @robobun, your commit 3360579 has 2 failures in Build #74684 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 34161

That installs a local version of the PR into your bun-34161 executable, so you can run:

bun-34161 --bun

@github-actions

Copy link
Copy Markdown
Contributor

Found 3 issues this PR may fix:

  1. https.Server.close callback is not always called #22490 - https.Server.close callback never fires on Windows; this PR fixes the KeepAlive ref being dropped prematurely during graceful stop, which on Windows prevents teardown events from delivering
  2. Bun process hangs when using Supertestwith Express — does not exit after test completion #23648 - Bun process hangs after server.close() with Supertest/Express on Windows; consistent with the event loop stopping I/O polling when the ref is released too early during request draining
  3. getTokenInteractive in @azure/msal-node will cause Bun to hang after the end of the script #30501 - Process hangs indefinitely on Windows after msal-node's internal HTTP server should have shut down; matches the KeepAlive ref mismanagement during graceful stop

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #22490
Fixes #23648
Fixes #30501

🤖 Generated with Claude Code

@robobun

robobun commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

Checked the bot's suggestions:

Keeping the PR scoped to #34158, which is verified fixed on Windows and has a cross-platform regression test.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 325e29e6-e10b-4516-a2b7-19b43832653f

📥 Commits

Reviewing files that changed from the base of the PR and between 60799c3 and 3360579.

📒 Files selected for processing (2)
  • test/expectations.txt
  • test/regression/issue/34158.test.ts

Walkthrough

Changes

Added Bun and Node HTTP shutdown regression tests covering aborted or half-closed requests, and removed Windows quarantine entries for related HTTP scenarios.

Server shutdown lifecycle

Layer / File(s) Summary
Bun server abort regression
test/regression/issue/34158.test.ts
Spawns a Bun server, stops it during a pending request, and verifies request abort handling and clean process termination.
Node HTTP teardown regression
test/regression/issue/34158.test.ts, test/expectations.txt
Tests half-closed response handling, client upload abort, and successful server.close() completion; removes related Windows expectations.

Possibly related issues

  • Issue 34158 — The tests directly cover the Windows server.close() hang and socket-abort scenarios described by the issue.

Possibly related PRs

  • oven-sh/bun#34356 — Addresses the node:http socket-end drain behavior exercised by the regression test.

Suggested reviewers: jarred-sumner

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: regression coverage for the server.close() teardown wedge in #34158.
Description check ✅ Passed The description covers what the PR does and includes concrete verification evidence, though it doesn't use the template's exact headings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/regression/issue/34158.test.ts`:
- Around line 36-41: Replace the fixed 50ms setTimeout in the net.connect
callback with synchronization on the actual request-start condition, awaiting
confirmation that the server has begun handling the request before destroying
the client. Preserve the test’s intended client-disconnect behavior and avoid
introducing any timer-based sequencing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e790afa3-2395-4921-a6b9-062c55b93b0a

📥 Commits

Reviewing files that changed from the base of the PR and between cc0c1e8 and 5bfcb6c.

📒 Files selected for processing (3)
  • src/runtime/server/mod.rs
  • test/expectations.txt
  • test/regression/issue/34158.test.ts
💤 Files with no reviewable changes (1)
  • test/expectations.txt

Comment thread test/regression/issue/34158.test.ts Resolved
Comment thread src/runtime/server/mod.rs Resolved
Comment thread src/runtime/server/mod.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both prior nits (H3-branch guard, redundant unref() in deinit_if_we_can) are addressed in 2bd97c7 and I found nothing new. Deferring to a human for sign-off given this changes event-loop ref release timing in the server shutdown path — the same area where #32488's attempts regressed.

What was reviewed:

  • stop_listening guards unref() on abrupt || pending_requests == 0 for both TCP and H3 arms; deferred release in deinit_if_we_can fires from on_request_complete → pending_requests -= 1 → deinit_if_we_can() (mod.rs:1440-1441).
  • Confirmed the WS-independent unref gate can't strand the ref: has_listener() is already false at that point and KeepAlive::unref is idempotent.
  • Regression test's setTimeout(dropClient, 50).unref() is now sequenced from inside the handler; the unref'd timer is the property under test, not a wait-for-time probe.
  • expect(stderr).toBe("") was flagged and ruled out — bunEnv quiets debug logs and no ASAN-gated skip is needed for this test.
Extended reasoning...

Overview

The PR changes two functions in src/runtime/server/mod.rs: stop_listening() now defers releasing the server's KeepAlive loop ref on graceful stop when pending_requests > 0, and deinit_if_we_can() releases it once requests drain (independent of active WebSockets). It adds a two-case regression test and un-quarantines a Windows entry in test/expectations.txt. The diff to deinit_if_we_can() is mostly re-indentation from nesting the existing !has_active_web_sockets() block inside the new outer gate; the substantive change is ~10 lines.

Security risks

None identified. No user input parsing, auth, or crypto is touched. The change gates when an existing idempotent unref() call fires; it does not introduce new resource acquisition or expose new surface area.

Level of scrutiny

High. This is production-critical server lifecycle code that governs whether the process stays alive after server.stop() / server.close(). Getting it wrong in one direction wedges Windows processes forever (the bug being fixed); getting it wrong in the other direction leaks a loop ref and prevents clean exit (what #32488's attempt 3 did with the WS-gated variant). The PR description explicitly documents that history, and the fix is deliberately narrower than the prior attempts, but this is exactly the class of change where a maintainer familiar with the pending_requests / active_tasks / uv-ref accounting should confirm the invariant.

Other factors

  • My two prior inline comments (H3 else-branch unguarded, redundant unref() made dead) were both addressed in commit 2bd97c7 via a shared should_unref_now local and folding the outer gate. Verified in the current diff.
  • I traced the deferred-release path: on_request_complete() (mod.rs:1435) and on_static_request_complete() (mod.rs:1429) both decrement pending_requests and call deinit_if_we_can(), so the held ref is released when the last in-flight request completes. stop() also calls deinit_if_we_can() at mod.rs:1590 for the zero-pending case.
  • One pre-existing site at server_body.rs:2788 decrements pending_requests without calling deinit_if_we_can() (a synchronous dev-tools JSON handler). It's synchronous native code where server.stop() can't interleave, so it's not affected by this change — noting it only as pre-existing.
  • The regression test's expect(stderr).toBe("") pattern was raised by a finder and ruled out; bunEnv sets BUN_DEBUG_QUIET_LOGS=1. The unref'd setTimeout in the first test case is intentional per the author's reply — it's the observable that distinguishes fixed from unfixed, not a timing probe.
  • CI build #72920 is in progress; no results visible yet in the timeline.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both nits from my earlier pass are addressed in 2bd97c7 (the H3-only arm now shares the should_unref_now guard, and the redundant unref() in deinit_if_we_can is gone). I didn't find anything further, but this reworks the server's event-loop KeepAlive release timing across graceful stop — subtle enough (and with a prior failed attempt in #32488) that a maintainer familiar with the server lifecycle should sign off.

What was reviewed:

  • stop_listening: both TCP and H3 arms now defer unref() on graceful stop with pending requests; abrupt stop still unrefs immediately.
  • deinit_if_we_can: the deferred unref() gates on pending_requests == 0 && !has_listener() only — checked that excluding has_active_web_sockets() is deliberate (WS close never reaches this function) so a stopped server with only WS connections doesn't hold the ref forever.
  • Confirmed KeepAlive::unref is a status flag, not a counter — the extra call from deinit_if_we_can after stop_listening already unref'd is a no-op, and the user-facing server.unref() path is unaffected.
Extended reasoning...

Overview

The PR changes when NewServer releases its KeepAlive loop ref during a graceful stop()/server.close(). Previously stop_listening() unconditionally called self.unref(); now it defers when !abrupt && pending_requests > 0, and deinit_if_we_can() releases it once the last request drains. The H3-only listener arm gets the same guard via a shared should_unref_now local. A regression test covers both Bun.serve (POSIX-observable early-exit) and node:http (Windows wedge), and the Windows quarantine entry for the original half-close test is removed.

Security risks

None identified. This is event-loop refcounting during shutdown; no auth, crypto, or untrusted-input parsing is touched.

Level of scrutiny

High. src/runtime/server/mod.rs is production-critical, and KeepAlive ref balance errors fail in two directions: hold too long → process never exits (the #32488 attempt-3 failure mode with ws-upgraded connections, which is why the new gate deliberately excludes has_active_web_sockets()); release too early → Windows uv_run stops polling and in-flight requests wedge (the #34158 bug). The reasoning that ServerWebSocket::on_close never reaches deinit_if_we_can() is load-bearing for the gate shape and deserves a maintainer's confirmation.

Other factors

  • My two prior inline nits (H3 sibling arm unguarded; now-dead second unref()) were both applied in 2bd97c7, and CodeRabbit's setTimeout-sequencing concern was addressed by moving the client-destroy schedule inside the handler.
  • The regression test asserts stderr === "", which CLAUDE.md warns against for ASAN/debug noise, but the PR's own evidence shows it passing on the ASAN debug pipeline, so not flagging it.
  • The fix is narrow and well-argued, with fails-before/passes-after evidence on both Linux and Windows and a broad set of adjacent tests re-run. I'm deferring purely on the criticality of the code path, not on any identified defect.

@robobun

robobun commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

CI on build 72927 is red on unrelated lanes only (all classified flaky/pre-existing by the scraper, plus two darwin one-offs: no-orphans.test.ts daemon-reap timeout on darwin-26-aarch64 and a serve-direct-readable-stream.test.ts "had no matches" filter glitch on darwin-14-x64). Both pass locally on the debug build; neither touches server shutdown. The regression test and the un-quarantined half-close test are green on every lane that ran them. Ready for review.

@robobun
robobun force-pushed the farm/f7c9dc88/windows-graceful-close-ref-hold branch from b8864c3 to 77c02b2 Compare July 17, 2026 03:56
@robobun robobun changed the title server: keep the loop ref through a graceful stop until in-flight requests drain server: apply the graceful-stop ref guard to the H3-only stop_listening arm Jul 17, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Beyond the inline nit: verified that hoisting should_unref_now above self.listener.take() is behavior-preserving for the TCP arm (the condition reads only pending_requests / has_active_web_sockets(), neither touched by take()), and that the deferred release in deinit_if_we_can() covers the H3-only defer (has_listener() checks h3_listener, already taken at that point). Leaving final sign-off to a human since this is server shutdown ref-counting and the H3-only arm itself isn't exercised by the new test.

Extended reasoning...

The Rust change hoists the existing #32488 guard into a should_unref_now local and applies it to the sibling H3-only branch of stop_listening(). I traced both arms: the TCP arm's semantics are unchanged (the hoisted condition's inputs are not mutated by listener.take() or the preceding h3_listener.take()/h3_app.close()), and the H3-only arm's deferred unref completes via deinit_if_we_can() at line ~1681 since has_listener() is false once both listeners are taken. The expectations.txt change is a pure stale-comment deletion. All prior review threads (mine and CodeRabbit's) are resolved in the current revision. Not auto-approving because this is critical-path server lifecycle code and, per the PR description, the H3-only arm being fixed has no direct test coverage.

Comment thread test/regression/issue/34158.test.ts Resolved
Comment thread test/regression/issue/34158.test.ts Resolved
@robobun
robobun force-pushed the farm/f7c9dc88/windows-graceful-close-ref-hold branch from bcab491 to bafc6fe Compare July 17, 2026 04:25
@robobun robobun changed the title server: apply the graceful-stop ref guard to the H3-only stop_listening arm test: add regression coverage for #34158 (server.close() teardown wedge) Jul 17, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — test-only regression coverage for a fix that already landed in #32488, plus removal of an orphaned expectations.txt comment block. All prior review nits (combined-object assertion, test.concurrent, timer sequencing) have been applied.

What was reviewed:

  • Both subprocess tests drain stdout/stderr/exited concurrently and assert as a combined object; await using handles cleanup.
  • The unref'd setTimeout(dropClient, 50) is armed from inside the fetch handler after server.stop(), so there's no arrival race; dropClient is assigned synchronously before any async callback can read it.
  • The expectations.txt deletion is a stale comment only — the quarantine line it described was already removed by #32488.
Extended reasoning...

Overview

This PR adds test/regression/issue/34158.test.ts with two test.concurrent subprocess cases guarding the server-teardown fix that merged in #32488, and removes a 7-line orphaned comment block from test/expectations.txt (the [ WINDOWS ] quarantine entry it described was already deleted by #32488, leaving the comment attached to nothing). No runtime code is touched — earlier revisions of this PR carried the src/runtime/server/mod.rs change, but that has since merged separately and been dropped from the diff.

Security risks

None. Test-only change spawning bunExe() subprocesses that bind 127.0.0.1:0; no external network, no auth/crypto/permissions surface.

Level of scrutiny

Low-to-moderate — the concern with regression tests is flakiness and whether they fail for the right reason. Both were examined:

  • Test 1 (Bun.serve): the client destroy is scheduled via an unref'd timer from inside the fetch handler, after server.stop(). The author explained (and CodeRabbit accepted) that the unref'd timer is itself the mechanism under test — whether the server's held ref keeps the loop alive long enough for it to fire. dropClient is assigned synchronously before the connect callback or fetch handler can run, so setTimeout(dropClient, 50) never sees undefined. The process.on("exit") reporter distinguishes SAW_ABORT from EXITED_EARLY, so a regression produces a clear diff rather than a hang.
  • Test 2 (node:http): awaits "listening" via once(), awaits server.close() via its callback, uses Buffer.allocUnsafe for the 10 MB body per harness conventions. On regression this would hang and hit the test timeout, which is the intended failure mode for the Windows wedge case.

Both tests use bunEnv/bunExe(), port: 0, await using proc, concurrent pipe draining via Promise.all, and a single combined { stdout, stderr, exitCode } assertion.

Other factors

Three rounds of review nits from prior runs (setTimeout sequencing, exact-empty-stderr assertion, test.concurrent) were each addressed in follow-up commits and all threads are resolved. The author reported CI green for this test on every lane that ran it (build 72927). The expectations.txt change is a pure comment deletion with no effect on which tests run.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — test-only regression coverage for a fix that already merged in #32488; both remaining inline findings are polish nits (stale EOF comment in expectations.txt, spawn timeout:/signalCode on the hang-guard case) and don't block.

Extended reasoning...

Overview

This PR is now test-only: it adds test/regression/issue/34158.test.ts (two subprocess-spawning cases guarding the server.stop()/server.close() KeepAlive-ref fix that landed in #32488) and removes one stale comment block from test/expectations.txt. Earlier revisions carried src/runtime/server/mod.rs changes; those merged separately and my prior inline comments on them are resolved.

Security risks

None. No production code is touched. The tests bind port: 0 on 127.0.0.1 inside a child process, contact no external hosts, and write no files.

Level of scrutiny

Low-to-moderate. The runtime fix is already on main; this PR only adds coverage. The tests follow harness conventions closely — bunEnv/bunExe, await using on the spawn, concurrent Promise.all pipe drain, combined {stdout, stderr, exitCode} assertion, test.concurrent — all of which were applied in response to earlier review rounds on this PR.

Other factors

All four of my prior inline comments (dead unref(), H3 else-arm, separate stderr assertion, test.concurrent) were addressed and are marked resolved. CodeRabbit's setTimeout-sequencing concern was also addressed by moving the timer arm inside the fetch handler. CI is green on the target lanes per the author's build-74490 note. The two findings this run are explicitly nits: one is a second orphaned comment block at EOF of expectations.txt (pure comment hygiene, zero runner impact), the other is adding a spawn timeout: + signalCode to the hang-guard test to match sibling regression files — diagnostic quality only, the test still fails on regression without it. Neither affects correctness, so I'm approving; the author can fold them in or leave for a follow-up.

Comment thread test/expectations.txt Resolved
Comment thread test/regression/issue/34158.test.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/regression/issue/34158.test.ts`:
- Line 60: Relax the subprocess result assertions in
test/regression/issue/34158.test.ts at lines 60-60 and 110-115 by matching
stderr with expect.any(String) instead of requiring an empty string; keep the
stdout and exitCode expectations unchanged at both sites.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 993f4160-82fa-4b2c-8163-209f582dca91

📥 Commits

Reviewing files that changed from the base of the PR and between bafc6fe and 60799c3.

📒 Files selected for processing (2)
  • test/expectations.txt
  • test/regression/issue/34158.test.ts
💤 Files with no reviewable changes (1)
  • test/expectations.txt

Comment thread test/regression/issue/34158.test.ts Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — test-only regression coverage plus stale-comment cleanup. The remaining inline note is a two-line consistency nit (test 1's spawn lacks the same timeout/signalCode guard applied to test 2 in 60799c3); non-blocking either way.

Extended reasoning...

Overview

This PR is now test-only: it adds test/regression/issue/34158.test.ts (two test.concurrent subprocess cases guarding the #32488 fix — Bun.serve graceful stop() with an in-flight request, and the canonical node:http half-close + server.close() wedge) and deletes two orphaned comment blocks from test/expectations.txt that #32488 left behind when it removed their quarantine entries. The runtime change that earlier revisions of this PR carried has already merged via #32488; the H3 sibling was split out per the PR description.

Security risks

None. No production code is touched. The expectations.txt diff is pure comment-line deletions — no quarantine entries are added or removed, so CI coverage is unchanged. The test spawns local subprocesses binding port: 0 on 127.0.0.1 with no external network contact.

Level of scrutiny

Low. Test-only additions plus comment hygiene in a runner-ignored section of expectations.txt. The test file has been through five rounds of review feedback (unref'd-timer sequencing, combined-object assertions, test.concurrent, second orphaned expectations block, hang-guard timeout/signalCode on test 2), each addressed and resolved. The tests follow the harness conventions closely: bunEnv/bunExe, await using proc, Promise.all pipe draining, port: 0, issue-URL header comment.

Other factors

The one open inline nit — test 1's spawn is missing the timeout: 10_000 + signalCode: null guard that 60799c3 added to test 2 — is a file-internal symmetry point with no correctness impact (test 1's regression mode is early-exit, not hang). CI is reported green on the latest build with the new test passing on all lanes that ran it. Approving; the nit can be taken or left.

Comment thread test/regression/issue/34158.test.ts Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — test-only regression coverage plus stale-comment cleanup; all prior review nits have been applied.

What was reviewed:

  • Both subprocess tests now follow the hang-guard convention (spawn timeout: 10_000, combined {stdout, stderr, exitCode, signalCode} assertion, test.concurrent, pipes drained via Promise.all).
  • expectations.txt deletions are comment-only; confirmed no live quarantine entries are removed and both orphaned #32488 comment blocks are now gone.
  • Checked test 1's client-drop sequencing (unref'd timer scheduled from inside the handler after server.stop()) — the abort await is bounded by the parent spawn timeout, so a delivery gap fails with a clear diff rather than a runner timeout.
Extended reasoning...

Overview

The PR adds test/regression/issue/34158.test.ts (two test.concurrent subprocess cases guarding the #32488 fix for the server.stop()/server.close() loop-ref release) and deletes 11 comment-only lines from test/expectations.txt that #32488 left orphaned when it removed their quarantine entries. No runtime source is touched — an earlier revision that patched src/runtime/server/mod.rs was dropped after #32488 merged the fix independently.

Security risks

None. This is test-only: a new regression test file and comment deletions in the CI expectations manifest. No production code paths, no user-facing surface, no input handling.

Level of scrutiny

Low. Test additions and comment cleanup carry no correctness risk to the shipped binary. The review focus was harness-convention conformance (REVIEW.md's subprocess/hang-guard rules) and confirming the expectations.txt deletions remove only dead comments, not live entries — both hold.

Other factors

Four rounds of prior inline nits from earlier runs (combined-object assertion, test.concurrent, spawn timeout + signalCode: null, sibling orphaned comment block, spawn symmetry) were each applied in commits bcab491, bafc6fe, 60799c3, and a0700f1; every thread is resolved. The CodeRabbit expect.any(String) suggestion was correctly declined with a reasoned reply and withdrawn. The bug-hunting system found nothing on the current head. No human reviewer has outstanding comments. The PR description's evidence block shows the tests passing under debug/ASAN.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — test-only regression coverage; all four prior review rounds have been addressed (combined-object asserts, test.concurrent, both orphaned expectations.txt comment blocks removed, and both spawns now bounded with timeout + signalCode: null, with the 30s bump for ASAN headroom in b593bb2).

Extended reasoning...

Overview

Test-only PR: adds test/regression/issue/34158.test.ts with two subprocess-spawned regression cases guarding the #32488 fix (Bun.serve graceful stop() keeping the loop ref while requests drain; node:http server.close() draining a half-closed connection), and removes two orphaned comment blocks from test/expectations.txt that #32488 left behind when it deleted their quarantine entries. No production code is touched — the runtime fix already landed in #32488 and this PR was rescoped to coverage-only after its earlier mod.rs changes were dropped.

Security risks

None. The change adds a test file and deletes comment lines from a CI expectations file. Both subprocess scripts bind port: 0 on 127.0.0.1 inside a child process spawned with bunEnv; no external hosts, no credentials, no filesystem writes.

Level of scrutiny

Low. Test-only, self-contained, follows the established test/regression/issue/ subprocess-spawn pattern (bunExe -e, await using proc, concurrent pipe drain via Promise.all, combined {stdout, stderr, exitCode, signalCode} assertion, bounded spawn timeout). The expectations.txt edits are pure comment deletions — the runner ignores comment lines, so there is no CI-coverage change.

Other factors

This PR has been through four prior review rounds from me, each addressed in a follow-up commit and marked resolved: combined-object assertions (bcab491), test.concurrent (bafc6fe), the second orphaned expectations.txt block + hang-guard timeout/signalCode on test 2 (60799c3), and symmetry on test 1's spawn (a0700f1). b593bb2 then widened both spawn timeouts to 30s for ASAN headroom. The CodeRabbit expect.any(String) suggestion was declined with a stated reason and CodeRabbit withdrew it. No outstanding comments remain. I re-checked test 1's dropClient assignment ordering — it's assigned synchronously before the async connect callback can fire, so the handler's setTimeout(dropClient, 50) always sees a defined function. The bug-hunting pass on the current revision found nothing.

@robobun
robobun force-pushed the farm/f7c9dc88/windows-graceful-close-ref-hold branch from b593bb2 to 60a6130 Compare July 17, 2026 11:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/regression/issue/34158.test.ts`:
- Around line 90-97: Update the request flow in the regression test to use a
deliberately non-terminating or flow-controlled upload, keeping the request
active until the client cancellation is observed. Replace the blanket catch with
assertions that verify the request is aborted/cancelled for the expected reason,
and perform this verification before calling server.close(); retain the promise
check for write() returning true.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 10425766-16ce-42c0-8a6d-d8bbf0339bed

📥 Commits

Reviewing files that changed from the base of the PR and between 60799c3 and 60a6130.

📒 Files selected for processing (2)
  • test/expectations.txt
  • test/regression/issue/34158.test.ts
💤 Files with no reviewable changes (1)
  • test/expectations.txt

Comment thread test/regression/issue/34158.test.ts Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — test-only regression coverage; all prior review nits have been addressed.

What was reviewed:

  • Both subprocess tests now use test.concurrent, combined {stdout, stderr, exitCode, signalCode} assertions, and a 30s spawn timeout with signalCode: null — the earlier asymmetry and hang-guard gaps are resolved.
  • expectations.txt change is comment-only (both #32488-orphaned blocks now removed); no quarantine entries touched, so no coverage change.
  • Checked the dropClient assignment ordering in test 1 — it's set synchronously before any I/O can reach the handler, so no undefined-at-call race.
Extended reasoning...

Overview

Test-only PR adding test/regression/issue/34158.test.ts (two test.concurrent subprocess cases guarding the #32488 fix for the server.stop()/server.close() loop-ref release) and removing two stale comment blocks from test/expectations.txt that #32488 orphaned. No production code is touched — the runtime fix already landed in #32488.

Security risks

None. This adds test coverage and deletes comments. Both subprocesses bind port: 0 on 127.0.0.1 inside the child, no external hosts, no filesystem writes, no auth/crypto/permissions surface.

Level of scrutiny

Low. Test-only, follows established harness conventions (bunEnv/bunExe, await using, Promise.all for concurrent pipe drain, combined-object assertion, spawn-side timeout bound with signalCode: null). The expectations.txt edit removes only comment lines — the runner ignores comments, so CI test selection is unchanged.

Other factors

This PR has been through four review rounds; every inline comment I raised (combined-object assertion, test.concurrent, second orphaned expectations.txt block, spawn timeout + signalCode on both spawns) was applied and the threads resolved. The most recent commit (60a6130) widened the spawn timeout to 30s for ASAN headroom, which is reasonable given the debug/ASAN evidence showed ~2.5s per test. CodeRabbit's remaining suggestion (relax stderr to expect.any(String)) was declined with a sound rationale and withdrawn. The bug-hunting pass on the current revision found nothing.

robobun added 4 commits July 17, 2026 19:49
The fix landed in #32488 (stop_listening holds the server's loop ref
while pending_requests > 0 or active WebSockets exist; WS close now
re-evaluates deinit_if_we_can so the deferred release completes).

Adds a two-case subprocess regression test:
 - Bun.serve: graceful stop() with an in-flight async handler must not
   let the process exit before the request's abort is observed.
 - node:http: the canonical half-close + client-abort + server.close()
   scenario must drain (previously wedged forever on Windows).

Also removes the now-stale expectations.txt comment block (#32488
removed the quarantine entry itself but left the comment).

The H3-only sibling arm of stop_listening is still unguarded on main;
testing it is blocked by an lsquic re-entrancy assertion on graceful
stop() of an http3-only server with a request in flight, handed off
separately.
…-guard test with a spawn timeout + signalCode assert
On debian-13 x64-asan the instrumented child's teardown pushed the 10 s
spawn timeout (stdout was already 'CLOSED'/'SAW_ABORT' so the scenario
under test passed; the SIGTERM came during exit). Bump both spawn
timeouts to 30 s and shrink the half-close body to 64 KB (the mechanism
is half-close-mid-upload, not the 10 MB size specifically).
@robobun

robobun commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-07-17, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main.

@robobun robobun closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant