Skip to content

net: support abort signal with BoundSocket - #68022

Open
Benphemeh wants to merge 1 commit into
nodejs:mainfrom
Benphemeh:fix/net-boundsocket-abort-signal-67855
Open

Benphemeh wants to merge 1 commit into
nodejs:mainfrom
Benphemeh:fix/net-boundsocket-abort-signal-67855

Conversation

@Benphemeh

Copy link
Copy Markdown

Summary

Fixes an issue where the signal option is silently ignored when a net.Server starts listening with a BoundSocket.

Server.prototype.listen() handles BoundSocket instances through an early-return path. This path bypasses the normal addServerAbortSignalOption() registration, meaning the supplied AbortSignal is never connected to the server lifecycle. Consequently, aborting the signal does not close the server, potentially leaving the process running with an active listening handle.

This change registers the abort-signal handling within the BoundSocket branch, before the socket handle is consumed. This preserves the existing ownership-transfer semantics while ensuring that signal validation and abort-listener registration happen before the server adopts the handle.

Implementation

  • Register the supplied abort signal in the BoundSocket handling path before calling kBoundSocketConsume().
  • Preserve the existing behaviour for other server.listen() paths.
  • Ensure invalid signal values are rejected before the BoundSocket is consumed.

Tests

Add regression coverage for:

  • TCP-backed BoundSocket instances aborted from the listening callback.
  • Immediate abortion after calling listen().
  • Signals that are already aborted before listening begins.
  • Invalid signal values, including verification that the BoundSocket remains unconsumed.
  • Pipe-backed BoundSocket instances.

Validation

  • python3 tools/test.py --mode=release parallel/test-net-boundsocket.js — passed.
  • python3 tools/test.py --mode=release parallel/test-net-server-listen-options-signal.js — passed.
  • Release build completed successfully.
  • git diff --check — passed.

Fixes: #67855

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Signed-off-by: Adewole oluwanifemi <beniphemeh11@yahoo.com>
@Benphemeh
Benphemeh force-pushed the fix/net-boundsocket-abort-signal-67855 branch from 9ae8083 to 96dfa8c Compare December 4, 2026 23:15
@Benphemeh

Copy link
Copy Markdown
Author

Thanks, @inoway46, for the confirmation and for encouraging me to proceed.

I've implemented the fix and opened a PR for review.

The issue was caused by the early-return path in Server.prototype.listen() for BoundSocket instances bypassing addServerAbortSignalOption(). I've addressed this by registering the abort-signal handling before the BoundSocket handle is consumed, ensuring that the signal is validated and correctly connected to the server lifecycle.

I've also added regression tests covering TCP and pipe-backed BoundSocket instances, immediate abort, pre-aborted signals, and invalid signal validation.

The Node.js release build completed successfully, and both relevant test suites passed:

  • parallel/test-net-boundsocket.js
  • parallel/test-net-server-listen-options-signal.js

Thanks again for the guidance. I'd appreciate your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

net: listening on a BoundSocket ignores signal

2 participants