Skip to content

net: surface errors from setKeepAlive handle calls - #65539

Open
waterWang wants to merge 2 commits into
nodejs:mainfrom
waterWang:fix-setkeepalive-error
Open

net: surface errors from setKeepAlive handle calls#65539
waterWang wants to merge 2 commits into
nodejs:mainfrom
waterWang:fix-setkeepalive-error

Conversation

@waterWang

Copy link
Copy Markdown

Fixes: #65529

`Socket.prototype.setKeepAlive()` ignored the error code returned by the
underlying handle, so a failed operation (e.g. a negative delay rejected by
the platform with `EINVAL`) reported success and returned the socket. The
adjacent `setTypeOfService()` already throws `ErrnoException` in this case.

This change makes `setKeepAlive()` consistent with `setTypeOfService()`:
when the handle returns a non-zero error and the platform is not Windows
(where keep-alive settings are best-effort), throw the `ErrnoException`.

A regression test stubs the handle to return `UV_EINVAL` and asserts the
error is surfaced with the right `code`/syscall.

@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 Aug 25, 2026

@jasnell jasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Technically I'm afraid this might be semver-major. I'm happy to consider it just a bug fix if others agree. @nodejs/tsc?

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.12%. Comparing base (54b4e37) to head (68ad950).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65539      +/-   ##
==========================================
- Coverage   90.13%   90.12%   -0.02%     
==========================================
  Files         751      751              
  Lines      253635   253638       +3     
  Branches    47786    47784       -2     
==========================================
- Hits       228615   228580      -35     
- Misses      16268    16310      +42     
+ Partials     8752     8748       -4     
Files with missing lines Coverage Δ
lib/net.js 94.56% <100.00%> (+<0.01%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

net: setKeepAlive() ignores the error returned by the handle

3 participants