Skip to content

http: re-check pending data before flushing on reused sockets - #67606

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:http-agent-recheck-pending-read
Open

ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:http-agent-recheck-pending-read

Conversation

@ShogunPanda

Copy link
Copy Markdown
Contributor

When an HTTP agent reuses a kept-alive socket, the request is flushed on a later tick than the one on which the socket was selected, and nothing re-checked the socket for unread data in between. Data arriving in that window could be read as the response to the new request.

This re-checks the reused socket for pending data immediately before the request is flushed: if there is any, the request fails with ECONNRESET instead of being sent on that socket. It also makes the pending-read probe cover Windows named pipes, using PeekNamedPipe(), as it already does on POSIX.

Adds regression tests for the pre-flush window, for reuse of a free socket that received unsolicited data, and for the pipe probe.

AI-assisted work. All changes reviewed by a human.

Re-check a reused socket for unread data immediately before the request is
flushed, since data can arrive between the Agent's selection of the socket and
the next tick. Also probe Windows named pipes with PeekNamedPipe() so they are
covered like on POSIX.

Assisted-By: OpenAI:GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Nov 19, 2026

@mcollina mcollina 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.

lgtm

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.72%. Comparing base (cdd0687) to head (75b93df).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67606      +/-   ##
==========================================
- Coverage   90.73%   90.72%   -0.01%     
==========================================
  Files         801      801              
  Lines      280794   280812      +18     
  Branches    54202    54211       +9     
==========================================
- Hits       254771   254767       -4     
- Misses      16202    16206       +4     
- Partials     9821     9839      +18     
Files with missing lines Coverage Δ
lib/internal/http/agent.js 96.63% <100.00%> (+<0.01%) ⬆️
lib/internal/http/client.js 97.11% <100.00%> (+<0.01%) ⬆️
src/stream_wrap.cc 86.10% <ø> (ø)

... and 33 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.

@ShogunPanda ShogunPanda added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants