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

Revert "net: don't normalize twice in Socket#connect()" #12852

Closed
wants to merge 2 commits into from

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented May 5, 2017

This reverts commit bb06add. This commit was causing failures in the async-listener module, which monkey patches Socket.prototype.connect().

cc: @watson @jasnell

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

net

This reverts commit bb06add.
This commit was causing failures in the async-listener module,
which monkey patches Socket.prototype.connect().
@nodejs-github-bot nodejs-github-bot added the net Issues and PRs related to the net subsystem. label May 5, 2017
@addaleax
Copy link
Member

addaleax commented May 5, 2017

Would it be okay if we only reverted this in v7.x?

@cjihrig
Copy link
Contributor Author

cjihrig commented May 5, 2017

Let's definitely revert on v7. Talking this over with @watson, one approach moving forward to avoid normalizing twice could be to detect when an array is passed. None of the public API signatures accept an array, but that is what is returned from normalizeArgs().

@watson
Copy link
Member

watson commented May 5, 2017

I'm currently working on a test to show this PR works. Afterwards I'll open a PR for passing the normalized args as an array from net.connect to Socket.prototype.connect.

This is important for people who monkey-patches
`Socket.prototype.connect` since it's not possible to monkey-patch
`net.connect` directly (as the core `connect` function is called
internally in Node instead of calling the `exports.connect` function).

Monkey-patching of `Socket.prototype.connect` is done by - among others
- most APM vendors, the async-listener module and the
continuation-local-storage module.
@cjihrig
Copy link
Contributor Author

cjihrig commented May 5, 2017

Regression test added, PTAL.

@bnoordhuis
Copy link
Member

I don't think it's okay to lock down our internal implementation for the benefit of third-party code. I'm alright with reverting this in v7.x but for 8.0 @watson should fix this in async-listener.

@joyeecheung
Copy link
Member

joyeecheung commented May 7, 2017 via email

watson added a commit to watson/node that referenced this pull request May 7, 2017
It's important for people who monkey-patch `Socket.prototype.connect`
that it's called by `net.connect` since it's not possible to
monkey-patch `net.connect` directly (as the `connect` function is called
directly by other parts of `lib/net.js` instead of calling the
`exports.connect` function).

Among the actors who monkey-patch `Socket.prototype.connect` are most
APM vendors, the async-listener module and the
continuation-local-storage module.

Related:
- nodejs#12342
- nodejs#12852
@watson
Copy link
Member

watson commented May 7, 2017

FYI, I've opened another PR #12861 that fixes this issue without reverting bb06add

@watson
Copy link
Member

watson commented May 7, 2017

@bnoordhuis I totally see your point and agree this isn't nice at all. I'd wish there were a better way to support this use-case.

I would have fixed this in userland if I could, but unfortunately I can't just monkey-patch net.connect as the internal connect function is called directly by other functions in lib/net.js (instead of calling the exports.connect function). In those situations, the monkey-patched version of the function will not be called.

Being able to trace outgoing tcp sockets is a huge deal for large parts of the Node community, so it's something we'll have to support. So far monkey-patching have been the way this was done from inside the process, so if we refactor the internals of lib/net.js so that monkey-patching is no longer possbile, a lot of people will be affected 😞

In the long run I like to see an API that could be exposed by core so that monkey-patching would no longer be necessary. For now I think #12861 is a good middle ground because it avoids reverting bb06add while not breaking the existing ecosystem 😃

@jkrems
Copy link
Contributor

jkrems commented May 7, 2017

Seconded, our internal instrumentation code also broke. Not sure if it would be possible to offer some official API/hook for achieving the same thing. But until that exists (or this change is reverted), we won't be able to test node 8 with our apps. :(

EDIT: Nvm, looks like #12861 is already on its way into master.

@cjihrig
Copy link
Contributor Author

cjihrig commented May 8, 2017

Closing this in favor of #12861

@cjihrig cjihrig closed this May 8, 2017
sam-github pushed a commit that referenced this pull request May 8, 2017
It's important for people who monkey-patch `Socket.prototype.connect`
that it's called by `net.connect` since it's not possible to
monkey-patch `net.connect` directly (as the `connect` function is called
directly by other parts of `lib/net.js` instead of calling the
`exports.connect` function).

Among the actors who monkey-patch `Socket.prototype.connect` are most
APM vendors, the async-listener module and the
continuation-local-storage module.

Related:
- #12342
- #12852

PR-URL: #12861
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Luca Maraschi <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
anchnk pushed a commit to anchnk/node that referenced this pull request May 19, 2017
It's important for people who monkey-patch `Socket.prototype.connect`
that it's called by `net.connect` since it's not possible to
monkey-patch `net.connect` directly (as the `connect` function is called
directly by other parts of `lib/net.js` instead of calling the
`exports.connect` function).

Among the actors who monkey-patch `Socket.prototype.connect` are most
APM vendors, the async-listener module and the
continuation-local-storage module.

Related:
- nodejs#12342
- nodejs#12852

PR-URL: nodejs#12861
Reviewed-By: Sam Roberts <[email protected]>
Reviewed-By: Luca Maraschi <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants