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: add new connection attempts events #51045

Merged
merged 1 commit into from Dec 21, 2023

Conversation

ShogunPanda
Copy link
Contributor

@ShogunPanda ShogunPanda commented Dec 4, 2023

This PR adds three new events in the net.createConnection flow:

  • connectionAttempt: Emitted when a new connection attempt is established. In case of Happy Eyeballs, this might emitted multiple times.
  • connectionAttemptFailed: Emitted when a connection attempt failed. In case of Happy Eyeballs, this might emitted multiple times.
  • connectionAttemptTimeout: Emitted when a connection attempt timed out. In case of Happy Eyeballs, this will not be emitted for the last attempt. This is not emitted at all if Happy Eyeballs is not used.

Additionally, a previous bug has been fixed where a new connection attempt could have been started after a previous one failed and after the connection was destroyed by the user. This led to a failed assertion.
This bug was reported several times but all were marked duplicates of the issue below.

Note that without the new events (especially connectionAttemptTimeout) I think is impossible to correctly test the bugfix.

Fixes: #48763

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Dec 4, 2023
@ShogunPanda
Copy link
Contributor Author

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

@ShogunPanda ShogunPanda changed the title net: do not attempt new connections when aborted net: added new connection attempts events Dec 5, 2023
@ShogunPanda ShogunPanda added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 5, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 5, 2023
@nodejs-github-bot
Copy link
Collaborator

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

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

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

@lpinca
Copy link
Member

lpinca commented Dec 9, 2023

I would not make these events public. If Happy Eyeballs will be moved to a lower level (libuv) in the future, it will be complex/useless to keep supporting them.

@ShogunPanda
Copy link
Contributor Author

@lpinca Are you just talking about removing them from the documentation?

@lpinca
Copy link
Member

lpinca commented Dec 9, 2023

Yes, or using private symbols. We can make them public later, if needed.

doc/api/net.md Outdated
Emitted when a connection attempt failed. This may be emitted multiple times
if the family autoselection algorithm is enabled in [`socket.connect(options)`][].

### Event: `'connectionAttemptFailed'`
Copy link
Member

Choose a reason for hiding this comment

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

Should this be connectionAttemptTimeout or whatever the third event was called. This appears to be an accidental duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is. Copy and paste lazyness. Fixed now.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

One doc nit that needs fixing, otherwise LGTM

@jasnell
Copy link
Member

jasnell commented Dec 9, 2023

If Happy Eyeballs will be moved to a lower level (libuv) in the future, it will be complex/useless to keep supporting them.

I presume these are added now because they are useful/needed now. Whether happy eyeballs is ever moved into libuv is still hypothetical AFAIK. I would rather not gate on this based on that hypothetical. We can deprecate these events in the future if necessary.

@lpinca
Copy link
Member

lpinca commented Dec 9, 2023

I have no objections, but if the events are only needed internally for testing/debugging why making them public? If people start using/abusing them, it will be hard to deprecate/remove them.

@ShogunPanda
Copy link
Contributor Author

@lpinca The events are, in my opinion, not just needed internally. At the moment we don't really have any events other than error and timeout (which are general purpose and operate on the higher level) to track what happens when establishing the connection. So I added them. Do you think are they dangerous in any way?

@ShogunPanda ShogunPanda added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 11, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 11, 2023
RafaelGSS pushed a commit that referenced this pull request Jan 2, 2024
PR-URL: #51045
Fixes: #48763
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
RafaelGSS added a commit that referenced this pull request Jan 2, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: TODO
@RafaelGSS RafaelGSS mentioned this pull request Jan 2, 2024
RafaelGSS added a commit that referenced this pull request Jan 2, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: #51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
RafaelGSS added a commit that referenced this pull request Jan 2, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: #51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
RafaelGSS added a commit that referenced this pull request Jan 2, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: #51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
RafaelGSS added a commit to RafaelGSS/node that referenced this pull request Jan 3, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) nodejs#50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) nodejs#50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) nodejs#51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) nodejs#50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) nodejs#51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) nodejs#51246

PR-URL: nodejs#51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
RafaelGSS added a commit that referenced this pull request Jan 5, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: #51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
RafaelGSS added a commit that referenced this pull request Jan 11, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: #51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
RafaelGSS added a commit that referenced this pull request Jan 15, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) #50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) #50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) #51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) #50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) #51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) #51246

PR-URL: #51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
added: REPLACEME
-->

* `ip` {number} The IP which the socket is attempting to connect to.
Copy link
Contributor

Choose a reason for hiding this comment

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

@ShogunPanda Looks like it should be * address {string}. Not number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. This has been fixed in #51490.

Medhansh404 pushed a commit to Medhansh404/node that referenced this pull request Jan 19, 2024
Notable changes:

doc:
  * (SEMVER-MINOR) add documentation for --build-snapshot-config (Anna Henningsen) nodejs#50453
lib,src,permission:
  * (SEMVER-MINOR) port path.resolve to C++ (Rafael Gonzaga) nodejs#50758
net:
  * (SEMVER-MINOR) add connection attempt events (Paolo Insogna) nodejs#51045
src:
  * (SEMVER-MINOR) support configurable snapshot (Joyee Cheung) nodejs#50453
src,permission:
  * (SEMVER-MINOR) add --allow-addon flag (Rafael Gonzaga) nodejs#51183
timers:
  * (SEMVER-MINOR) export timers.promises (Marco Ippolito) nodejs#51246

PR-URL: nodejs#51342
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
@bradzacher
Copy link

bradzacher commented Feb 5, 2024

This looks like it's been baking in v21.6.0 for a few weeks now - is it going to be back-ported to v20 at all? (I noticed the lts-watch tag so I assume "probably"?)
If yes - is there a rough timeline on that?

@ShogunPanda
Copy link
Contributor Author

It should: I think this will happen in couple of weeks.

@lamuertepeluda
Copy link

It should: I think this will happen in couple of weeks.

it didn't get merged yet with the latest v20.11.1, didn't it? 🫤

@marco-ippolito
Copy link
Member

It should: I think this will happen in couple of weeks.

it didn't get merged yet with the latest v20.11.1, didn't it? 🫤

No it was a security release, there will be a release in a couple of weeks

@ArnoldZokas
Copy link
Contributor

@marco-ippolito any news on the next 20.x release? There is no release proposal for it yet, so at least another two weeks?

@jakubm-canva
Copy link

@marco-ippolito could you please provide an update. We're now approaching 4 weeks since the latest update requests, which remained unanswered.

richardlau pushed a commit that referenced this pull request Mar 25, 2024
PR-URL: #51045
Fixes: #48763
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
@richardlau richardlau mentioned this pull request Mar 25, 2024
@bradzacher
Copy link

Looks like this has released in 20.12.0
https://nodejs.org/en/blog/release/v20.12.0#new-connection-attempt-events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lts-watch-v20.x PRs that may need to be released in v20.x needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERR_INTERNAL_ASSERTION in internalConnectMultiple