Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait a macrotick to resume without pipelining #1465

Merged
merged 2 commits into from May 25, 2022
Merged

fix: wait a macrotick to resume without pipelining #1465

merged 2 commits into from May 25, 2022

Conversation

mcollina
Copy link
Member

This change makes the Client wait for a full macrotick before
executing up the next request if pipelining is disabled.
This is to account for socket errors events that might be waiting
to be processed in the event queue. This is the expected behavior
without pipelining.

This will slow us down a bit without pipelinig.

Fixes: #1415
Signed-off-by: Matteo Collina hello@matteocollina.com

This change makes the Client wait for a full macrotick before
executing up the next request if pipelining is disabled.
This is to account for socket errors events that might be waiting
to be processed in the event queue. This is the expected behavior
without pipelining.

This will slow us down a bit without pipelinig.

Fixes: #1415
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina requested a review from ronag May 24, 2022 14:53
@mcollina
Copy link
Member Author

@pimterry could you verify if this matches your expectations?

@ronag please review, this might have unwanted outcomes.

@mcollina mcollina changed the title Wait a macrotick to resume without pipelining fix: ait a macrotick to resume without pipelining May 24, 2022
@mcollina mcollina changed the title fix: ait a macrotick to resume without pipelining fix: wait a macrotick to resume without pipelining May 24, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 24, 2022

Codecov Report

Merging #1465 (661ac41) into main (4684a15) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1465      +/-   ##
==========================================
+ Coverage   94.51%   94.54%   +0.02%     
==========================================
  Files          49       49              
  Lines        4269     4271       +2     
==========================================
+ Hits         4035     4038       +3     
+ Misses        234      233       -1     
Impacted Files Coverage Δ
lib/client.js 97.89% <100.00%> (+<0.01%) ⬆️
lib/fetch/request.js 86.38% <0.00%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4684a15...661ac41. Read the comment docs.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Copy link
Contributor

@pimterry pimterry left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @mcollina! Yes, this solves my issue and looks sensible to me 👍

} else if (client[kPipelining] === 1) {
// We must wait a full event loop cycle to reuse this socket to make sure
// that non-spec compliant servers are not closing the connection even if they
// said they won't.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just nitpicking this comment: I think closing the connection without warning is actually spec-complaint for the server. Servers are free to close connections on a whim, no matter what. Persistence is encouraged where possible, but not strictly required at all times.

From https://httpwg.org/specs/rfc7230.html#rfc.section.6.5:

A client, server, or proxy MAY close the transport connection at any time.

Copy link
Member Author

Choose a reason for hiding this comment

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

The server in the text/example close the connection while sending Connection: Keep-Alive header, which is in contrast with https://datatracker.ietf.org/doc/html/rfc7230#section-6.3/. Basically the server is communicating to the client that it supports persistent connections while it does not as it closes every incoming connection immediately.

Implementing the behavior you want in a spec-compliant way would be to set a Connection: close header. This is already covered in undici.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ronag wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @mcollina

@mcollina mcollina merged commit 90d7821 into main May 25, 2022
@mcollina mcollina deleted the fix-1415 branch May 25, 2022 09:00
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* Wait a macrotick to resume without pipelining

This change makes the Client wait for a full macrotick before
executing up the next request if pipelining is disabled.
This is to account for socket errors events that might be waiting
to be processed in the event queue. This is the expected behavior
without pipelining.

This will slow us down a bit without pipelinig.

Fixes: nodejs#1415
Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* Wait a macrotick to resume without pipelining

This change makes the Client wait for a full macrotick before
executing up the next request if pipelining is disabled.
This is to account for socket errors events that might be waiting
to be processed in the event queue. This is the expected behavior
without pipelining.

This will slow us down a bit without pipelinig.

Fixes: nodejs#1415
Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* Wait a macrotick to resume without pipelining

This change makes the Client wait for a full macrotick before
executing up the next request if pipelining is disabled.
This is to account for socket errors events that might be waiting
to be processed in the event queue. This is the expected behavior
without pipelining.

This will slow us down a bit without pipelinig.

Fixes: nodejs#1415
Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undici fetch fails with sequential requests if the connection was closed
4 participants