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

net: simplify server.close() behavior when closing unopened server. #34042

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkrawczuk
Copy link
Contributor

I see no use case for behavior where an error is thrown in case a callback is
registered for a close event on a closed server. This is bizarre and unusual.

Originally, this behavior was introduced along with commit 984dc05 in order
to mimic net_legacy behavior. net_legacy for stdio was replaced by uv_net in
Node 0.5.7 (2011 AD.).

Up until commit f1dc55d, an error would be thrown synchronously if attempt
has been made to close an unopen server. The change would introduce the current
behavior.

This is a breaking API change and should most likely be introduced in a major
update.

  • 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 errors Issues and PRs related to JavaScript errors originated in Node.js core. net Issues and PRs related to the net subsystem. labels Jun 24, 2020
@mkrawczuk
Copy link
Contributor Author

This PR seems to have gotten a little stuck. Is there anything that should be done to move further?
cc: @addaleax

@mkrawczuk mkrawczuk requested a review from a team as a code owner August 10, 2020 16:06
@mkrawczuk mkrawczuk requested a review from a team August 10, 2020 16:06
@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 10, 2020
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

Copy link
Member

@trivikr trivikr left a comment

Choose a reason for hiding this comment

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

LGTM, some minor nits for typos

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

@mkrawczuk
Copy link
Contributor Author

Seems to be stuck again. @nodejs/net, @mcollina ?

@mcollina
Copy link
Member

@mkrawczuk this needs rebasing.

@nodejs/tsc given this is semver-major, I kindly ask for another review.

@mcollina mcollina requested review from jasnell and removed request for a team December 16, 2020 15:59
@mkrawczuk
Copy link
Contributor Author

@mcollina resolved conflicts via the github interface. I hope this does also rebase.

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 16, 2020
jasnell
jasnell previously approved these changes Dec 16, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 16, 2020
@nodejs-github-bot
Copy link
Collaborator

@mcollina mcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 16, 2020
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 16, 2020
@github-actions
Copy link
Contributor

Commit Queue failed
- Loading data for nodejs/node/pull/34042
✔  Done loading data for nodejs/node/pull/34042
----------------------------------- PR info ------------------------------------
Title      net: simplify server.close() behavior when closing unopened server. (#34042)
Author     Mateusz Krawczuk  (@mkrawczuk)
Branch     mkrawczuk:net_server_close_simplify -> nodejs:master
Labels     errors, net, semver-major
Commits    5
 - net: simplify server.close() behavior when closing unopened server.
 - Update test/parallel/test-net-server-close.js
 - Update test/parallel/test-net-server-close.js
 - Update test/parallel/test-net-server-close.js
 - Merge branch 'master' into net_server_close_simplify
Committers 2
 - Mateusz Krawczuk 
 - GitHub 
PR-URL: https://github.com/nodejs/node/pull/34042
Reviewed-By: Matteo Collina 
Reviewed-By: Trivikram Kamat 
Reviewed-By: James M Snell 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/34042
Reviewed-By: Matteo Collina 
Reviewed-By: Trivikram Kamat 
Reviewed-By: James M Snell 
--------------------------------------------------------------------------------
   ✔  Last GitHub Actions successful
   ℹ  Last Full PR CI on 2020-12-16T17:03:04Z: https://ci.nodejs.org/job/node-test-pull-request/34973/
- Querying data for job/node-test-pull-request/34973/
✔  Build data downloaded
   ✖  1 failure(s) on the last Jenkins CI run
   ℹ  This PR was created on Wed, 24 Jun 2020 16:33:28 GMT
   ✔  Approvals: 3
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/34042#pullrequestreview-486914209
   ✔  - Trivikram Kamat (@trivikr): https://github.com/nodejs/node/pull/34042#pullrequestreview-486490387
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/34042#pullrequestreview-553860517
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/426377355

@github-actions github-actions bot added the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Dec 16, 2020
@nodejs-github-bot
Copy link
Collaborator

@mcollina mcollina added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Dec 16, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 16, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@mkrawczuk
Copy link
Contributor Author

Huh? There seems to be a merge conflict in Jenkins job, file lib/net.js. @mcollina do you have an idea for fixing it?

@mcollina
Copy link
Member

Huh? There seems to be a merge conflict in Jenkins job, file lib/net.js. @mcollina do you have an idea for fixing it?

No

@mkrawczuk
Copy link
Contributor Author

But is it a PR problem or Jenkins problem?

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 18, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 18, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@mcollina
Copy link
Member

This seems to not apply cleanly on master.

13:03:23 Falling back to patching base and 3-way merge...
13:03:23 Auto-merging lib/net.js
13:03:23 CONFLICT (content): Merge conflict in lib/net.js
13:03:23 Auto-merging lib/internal/errors.js
13:03:23 Auto-merging doc/api/net.md
13:03:23 Auto-merging doc/api/errors.md
13:03:23 error: Failed to merge in the changes.
13:03:23 Patch failed at 0001 net: simplify server.close() behavior when closing unopened server.
13:03:23 Use 'git am --show-current-patch' to see the failed patch

Can you please rebase this on top of master?

@mkrawczuk
Copy link
Contributor Author

Hmm, indeed. I have re-rebased it and now it should be all right.

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2020
@ronag ronag removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2020
Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

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

This contains a lot of unrelated commits. Bad rebase/merge?

@mkrawczuk mkrawczuk force-pushed the net_server_close_simplify branch from 59a3a94 to b0e2b2e Compare December 23, 2020 11:29
@mkrawczuk
Copy link
Contributor Author

Yep, bad merge/rebase. Now it looks alright. cc @ronag @mcollina


if (typeof cb === 'function') {
this.once('close', cb);
}
Copy link
Member

Choose a reason for hiding this comment

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

@mcollina: This change means that the callback won't always be invoked. Isn't that considered an anti pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as callback is a function, it will be called. Or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

@ronag is right. If there is no _handle yet the callback will not be called.

I see no use case for behavior where an error is thrown in case a callback is
registered for a `close` event on a closed server. This is bizarre and unusual.

Originally, this behavior was introduced along with commit 984dc05 in order
to mimic net_legacy behavior. net_legacy for stdio was replaced by uv_net in
Node 0.5.7 (2011 AD.).

Up until commit f1dc55d, an error would be thrown synchronously if attempt
has been made to close an unopen server. The change would introduce the current
behavior.

This is a breaking API change and should most likely be introduced in a major
update.
@mkrawczuk mkrawczuk force-pushed the net_server_close_simplify branch from b0e2b2e to b86ca35 Compare January 16, 2021 13:34
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.

Now that I see this, I agree with @ronag. A user would expect that a callback is called.

This change is likely not correct as it is right now.


// Ensure that the close callback is not called when the server was not
// previously running.
server.close(common.mustNotCall());
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. We should always call the callback.

Copy link

Choose a reason for hiding this comment

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

@mcollina could you please clarify why we need to close the server if that server is not running?

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I agree with Matteo. The callback here should be called in case there is any cleanup logic that is deferred to close (e.g. closing fd's). There's a non-trivial risk of breakage here and I don't see this change as being worth it now that I reconsider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. 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.

7 participants