FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

http: fix keep-alive not timing out after post-request empty line by islandryu · Pull Request #58178 · nodejs/node · GitHub

/ node Public

http: fix keep-alive not timing out after post-request empty line - #58178

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
islandryu:fix/httpEmptyLine
Jun 24, 2025
Merged

http: fix keep-alive not timing out after post-request empty line#58178
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
islandryu:fix/httpEmptyLine

Conversation

Copy link
Copy Markdown
Member

Fixes: #58140

As shown in the test code, sending an empty line after a request can result in a state where the keep-alive timer is reset, but neither requestTimeout nor keepAliveTimeout is active.
Unless a custom timeout is implemented, this allows the client to hold the socket indefinitely.

Modified behavior so that data like an empty line, which does not indicate the start of an HTTP message, no longer resets the keep-alive timeout.

FYI

Here is the behavior of other HTTP servers:

nginx: When client_header_timeout is set, sending an empty line after a request triggers a 408 timeout response once the timeout period expires.

Apache: When RequestReadTimeout header=5-10,MinRate=500 is configured, the connection times out after the specified duration, but no error code is sent.

However, since the timing for resetting the keep-alive timeout is not clearly defined in RFC 9112 or similar specifications, I believe this change is appropriate.

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

nodejs-github-bot added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels May 5, 2025

Copy link
Copy Markdown
Member Author

node/lib/_http_server.js

Lines 1040 to 1041 in c46b2b9

function parserOnIncoming(server, socket, state, req, keepAlive) {
resetSocketTimeout(server, socket, state);

The timing for resetting the keep-alive timeout should be limited to this part—specifically, when llhttp determines that parsing is necessary.

codecov Bot commented May 5, 2025
edited
Loading

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.13%. Comparing base (a36981a) to head (350b680).
Report is 460 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58178      +/-   ##
==========================================
- Coverage   90.21%   90.13%   -0.09%     
==========================================
  Files         630      630              
  Lines      186391   186782     +391     
  Branches    36608    36654      +46     
==========================================
+ Hits       168161   168357     +196     
- Misses      11052    11203     +151     
- Partials     7178     7222      +44     
Files with missing lines Coverage Δ
lib/_http_server.js 97.06% <ø> (-0.01%) ⬇️

... and 78 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 added the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2025
github-actions Bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels May 5, 2025

github-actions Bot commented May 5, 2025

Copy link
Copy Markdown
Contributor
Failed to start CI
   ⚠  No approving reviews found
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/14841662619


server.listen(0);

const client = connect({

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would create the connection after the server emits the 'listening' event.

}, 100);

client.on('data', (data) => {
const status = data.toString().split(' ')[1];

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is no guarantee that all data will be received in a single chunk.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thx, fixed test code.

ShogunPanda 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM!

ShogunPanda added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels May 9, 2025
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 9, 2025

Copy link
Copy Markdown
Collaborator

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Lgtm

mcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label May 9, 2025

Copy link
Copy Markdown
Collaborator

RafaelGSS added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label May 9, 2025
nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels May 9, 2025

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/58178
✔  Done loading data for nodejs/node/pull/58178
----------------------------------- PR info ------------------------------------
Title      http: fix keep-alive not timing out after post-request empty line (#58178)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     islandryu:fix/httpEmptyLine -> nodejs:main
Labels     http, author ready, needs-ci
Commits    2
 - http: fix keep-alive not timing out after post-request empty line
 - fix test
Committers 1
 - islandryu <shimaryuhei@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/58178
Fixes: https://github.com/nodejs/node/issues/58140
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/58178
Fixes: https://github.com/nodejs/node/issues/58140
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Mon, 05 May 2025 08:46:23 GMT
   ✔  Approvals: 2
   ✔  - Paolo Insogna (@ShogunPanda) (TSC): https://github.com/nodejs/node/pull/58178#pullrequestreview-2829062997
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/58178#pullrequestreview-2829334728
   ✘  Last GitHub CI failed
   ℹ  Last Full PR CI on 2025-05-09T18:21:27Z: https://ci.nodejs.org/job/node-test-pull-request/66736/
- Querying data for job/node-test-pull-request/66736/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/14936022305

Copy link
Copy Markdown
Contributor

@islandryu Can you please fix failing test so we can move this forward?

Copy link
Copy Markdown
Member Author

@ShogunPanda
Sorry, I should have mentioned you, but I’ve already made the fix here.
#58324

Separately, I used to be able to view the Jenkins results until recently, but now I’m getting a permission error and can no longer access them.
Do you know what might be causing this?

lpinca commented May 15, 2025

Copy link
Copy Markdown
Member

CI is under security embargo.

Copy link
Copy Markdown
Contributor

No worries, let's wait for the other PR to land and then you can rebase this.

About your question, maybe @nodejs/build-infra has some idea?

islandryu added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 21, 2025
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 21, 2025

Copy link
Copy Markdown
Collaborator

islandryu added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jun 24, 2025
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 24, 2025
nodejs-github-bot merged commit 057b4b5 into nodejs:main Jun 24, 2025

Copy link
Copy Markdown
Collaborator

Landed in 057b4b5

janakj commented Jun 24, 2025

Copy link
Copy Markdown

Thank you very much for fixing this!

RafaelGSS pushed a commit that referenced this pull request Jun 24, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 21, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 24, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Aug 18, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Aug 20, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
if (responseBuffer.includes('\r\n\r\n')) {
const statusLine = responseBuffer.split('\r\n')[0];
const status = statusLine.split(' ')[1];
assert.strictEqual(status, '404');

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This has been flaking the CI for over a month #59577

marco-ippolito pushed a commit that referenced this pull request Aug 23, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Mar 2, 2026
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Mar 3, 2026
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Mar 4, 2026
Fixes: #58140
PR-URL: #58178
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
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

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. http Issues or 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.

Timers headersTimeout and requestTimeout not restarted on keep-alive HTTP connections

8 participants


Back | FazBrowse Home | New Git URL