fix(http): raw 'upgrade' + tls.TLSSocket + destroy no longer hangs the event loop (#5010)#5018
Merged
Merged
Conversation
…ed raw-upgrade socket stops pinning the event loop (#5010) test-http-upgrade-reconsume-stream regressed to a hang after #5001/#4973: a raw HTTP 'upgrade' now hands the listener a real net.Socket adopted into perry-ext-net, and `new tls.TLSSocket(socket); server.close(); socket.destroy()` left a live handle pinning the loop (exit 124 instead of 0). Two perry-stdlib/perry-ext-net duplicate-symbol ('twin') hazards were at play: - socket.destroy() dynamic-dispatched through js_net_socket_destroy, whose symbol the bundled stdlib net shadows, so the adopted socket was marked destroyed in stdlib's empty registry and stayed alive in ext-net's. - the adopted socket's Close event sat in ext-net's own pending-event queue, which the unreliable aux pump / shadowed js_net_process_pending never drained. For an http-only program perry-stdlib runs its OWN bundled net, so its external-net-pump arm never touches ext-net's queue. The behavior even flipped with unrelated code-size changes (link-order roulette). Fix: give the destroy + queue-drain entry points DISTINCT, twin-free #[no_mangle] symbols (js_ext_net_destroy_socket / js_ext_net_drain_pending), route the handle-dispatch + aux pump through them, and drain ext-net's queue from the http-server pump (js_node_http_server_process_pending) — which runs every tick via external-http-server-pump and directly depends on perry-ext-net. Deterministic now: repro exits 0 across repeated runs and independent rebuilds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5010.
Summary
test-http-upgrade-reconsume-streamregressed to a hang (exit 124 instead of 0) after #5001/#4973. The repro:#4973 made a raw
'upgrade'hand the listener a realnet.Socketadopted intoperry-ext-net(adopt_upgraded_tcp_stream). Destroying it left a live handle pinning the loop. (Thenew tls.TLSSocket(socket)wrap named in the title is a red herring — the hang reproduces without it.)Root cause — perry-stdlib/perry-ext-net duplicate-symbol ("twin") hazards
Both crates export the same
#[no_mangle]net symbols; in a workspace/auto-optimize link the bundled-stdlib twin wins, and two things broke for the adopted socket:socket.destroy()dynamic-dispatched throughjs_net_socket_destroy→ bound to stdlib's twin → marked the socket destroyed in stdlib's empty registry while it stayeddestroyed=false(alive) in ext-net's.Closeevent sat in ext-net's own pending-event queue, which nothing reliably drained. For an http-only program perry-stdlib runs its own bundled net, so itsexternal-net-pumparm never touches ext-net's queue, and the ext-net aux pump proved unreliable across link layouts — the behavior even flipped with unrelated code-size changes (link-order roulette).Fix
#[no_mangle]symbols:js_ext_net_destroy_socket/js_ext_net_drain_pending(the original externs now delegate to them).destroyarm and the aux pump through those unique symbols.js_node_http_server_process_pending) — it runs every tick viaexternal-http-server-pumpand directly depends on perry-ext-net, so the call is a plain crate-path call to a symbol with no twin.Verification
netecho data flow is unchanged (actually more reliable than pristine in spot checks). The pre-existingnet-program close-hang is unrelated and out of scope.cargo test -p perry-ext-net: 8 passed.Code-only — version bump + changelog left for the maintainer to fold at merge.