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

http: add test case for req-res close ordering #36645

Merged
merged 1 commit into from
Jan 6, 2021

Conversation

dnlup
Copy link
Contributor

@dnlup dnlup commented Dec 27, 2020

Since the PR #33035 has changed the ordering of the close event, add a test case.
IncomingMessage will emit close before the response is sent in case the server is consuming data from it.
See comment #33035 (comment)


As @kanongil pointed out, IncomingMessage is emitting close before the response when the server attaches a handler to the request data event. Otherwise, the order is the same as it was before the change in the linked PR.

The test should catch eventual regressions, but let's also use this as a point for discussing this behavior further, if needed.

@ronag @mcollina

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 27, 2020
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

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

LGTM if all the added tests pass reliably.

@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Dec 27, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 27, 2020
@nodejs-github-bot
Copy link
Collaborator

@ronag ronag requested a review from mcollina December 27, 2020 19:17
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@dnlup
Copy link
Contributor Author

dnlup commented Dec 28, 2020

LGTM if all the added tests pass reliably.

Thinking out loud about the tests, I am wondering if this behavior could cause problems. In the first two cases res emits close after req, while in the last one is the other way around, as already pointed out. In the previous implementation, it seems that the order was always the same.

@dnlup
Copy link
Contributor Author

dnlup commented Dec 28, 2020

I added a few more comments.

@dnlup dnlup force-pushed the fix/regression_test_http_incoming branch from b415015 to 5b2c944 Compare December 28, 2020 10:22
@mcollina
Copy link
Member

I still think this behavior is ok. I would like to know a few arguments on why this is bad (minus it was a breaking change as a minor).

@dnlup
Copy link
Contributor Author

dnlup commented Dec 28, 2020

I still think this behavior is ok. I would like to know a few arguments on why this is bad (minus it was a breaking change as a minor).

My concern is with framework/libraries that might expect a strict ordering, always. I don't know if that is a good practice or not. This behavior broke hapi, but I tested fastify out of curiosity, and it didn't suffer the same issue. TLDR, I hope this doesn't complicate things too much in codebases that broke because of this change (i.e., when a fix would have to be implemented on their side). That's all I can say. I don't have a deep knowledge of hapi internals to expand more on that atm. Maybe I just got a little worried after yesterday.

@mcollina
Copy link
Member

@cjihrig wdyt? I don't really understand how Hapi relies on this specific ordering of things.

@kanongil
Copy link
Contributor

kanongil commented Dec 28, 2020

I did the analysis for hapi and can elaborate.

Hapi adds a 'close' listener to the http.IncomingRequest and will terminate the response processing when this is emitted. This broke since req would suddenly close as soon as all incoming data was processed.

The specific ordering of the req & res 'close' emits are irrelevant, since hapi only listens to the req event. Other frameworks are not affected because they don't take the same holistic approach that hapi does.

Note that for hapi I tried to change this to listen on the 'close' event of the http.ServerResponse instead. This fixed the issue, except for an upload socket close test that is most likely wrong (it uses synthesized req / res and events).

@dnlup
Copy link
Contributor Author

dnlup commented Dec 28, 2020

Thank you @kanongil for the analysis. It was very helpful.

@mcollina
Copy link
Member

@kanongil could you confirm that there is no significant issue with that change shipping in Node.js v16?

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 3, 2021
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 3, 2021
@nodejs-github-bot
Copy link
Collaborator

@dnlup
Copy link
Contributor Author

dnlup commented Jan 4, 2021

I can't see on https://ci.nodejs.org/ why those 3 jobs are failing, unfortunately.

@nodejs-github-bot
Copy link
Collaborator

@mcollina mcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 5, 2021
@github-actions github-actions 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 Jan 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2021

Commit Queue failed
- Loading data for nodejs/node/pull/36645
✔  Done loading data for nodejs/node/pull/36645
----------------------------------- PR info ------------------------------------
Title      http: add test case for req-res close ordering (#36645)
Author     Daniele Belardi  (@dnlup)
Branch     dnlup:fix/regression_test_http_incoming -> nodejs:master
Labels     author ready, test
Commits    1
 - http: add test case for req-res close ordering
Committers 1
 - Daniele Belardi 
PR-URL: https://github.com/nodejs/node/pull/36645
Reviewed-By: Rich Trott 
Reviewed-By: Robert Nagy 
Reviewed-By: Matteo Collina 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/36645
Reviewed-By: Rich Trott 
Reviewed-By: Robert Nagy 
Reviewed-By: Matteo Collina 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - http: add test case for req-res close ordering
   ✔  Last GitHub Actions successful
   ℹ  Last Full PR CI on 2021-01-04T21:19:02Z: https://ci.nodejs.org/job/node-test-pull-request/35251/
- Querying data for job/node-test-pull-request/35251/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
   ℹ  This PR was created on Sun, 27 Dec 2020 18:06:44 GMT
   ✔  Approvals: 3
   ✔  - Rich Trott (@Trott) (TSC): https://github.com/nodejs/node/pull/36645#pullrequestreview-558953069
   ✔  - Robert Nagy (@ronag): https://github.com/nodejs/node/pull/36645#pullrequestreview-558953108
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/36645#pullrequestreview-558962536
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/463731724

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jan 5, 2021
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 5, 2021
Since 55e83cb
has changed the ordering of the close event, add a test case.
IncomingMessage will emit close before the response is sent in case the
server is consuming data from it.

Refs: nodejs#33035 (comment)

PR-URL: nodejs#36645
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@aduh95 aduh95 force-pushed the fix/regression_test_http_incoming branch from 5b2c944 to ddac3bd Compare January 6, 2021 10:27
@aduh95
Copy link
Contributor

aduh95 commented Jan 6, 2021

Landed in ddac3bd

@aduh95 aduh95 merged commit ddac3bd into nodejs:master Jan 6, 2021
danielleadams pushed a commit that referenced this pull request Jan 12, 2021
Since 55e83cb
has changed the ordering of the close event, add a test case.
IncomingMessage will emit close before the response is sent in case the
server is consuming data from it.

Refs: #33035 (comment)

PR-URL: #36645
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@danielleadams danielleadams mentioned this pull request Jan 12, 2021
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 pending requests for changes, and a CI started. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants