-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: add warning for socket.connect reuse #33204
Conversation
`socket.connect` is subtly broken due to timing and _undestroy issues. Discourage usage and ask users to instead create a new socket instance. Refs: nodejs#33203
d448671
to
76bf3dd
Compare
Might have to deprecate |
I appreciate the subtle problems it introduces in terms of state, but thorough review of ecosystem use-cases would be required, this is a long-standing feature. cc: @bnoordhuis who might have perspective on uses this is put to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
-1 Creating a new socket is not always a solution, especially if there are event handlers to carry over, user-added properties to carry over, etc. I think it would be better to come up with a solution to fix whichever edge cases instead of deprecating |
In addition, I think there are options that can only be passed to the |
I favor this direction but there are a ton of details to figure out. |
But it is possible to workaround this. Just create your own socket wrapper.
This has been broken for quite a while and no one has fixed it. I think it's better to deprecate than leaving it broken.
What options are those? We should fix so that |
Anything specific in mind? Other than the constructor situation? |
Addressing a regression (#25969) with a method deprecation does not seem the proper way to fix it to me. What's wrong with |
This has been an issue for a long time. Last time we discussed it we basically came to the conclusion that this use case should be very unusual and its not worth fixing. It just became relevant again given that issue.
When re-using the socket, i.e. calling |
That's an understatement. :-)
I agree with Luigi that deprecation because of bugs isn't a fix. The original I appreciate it's non-trivial to untangle but deprecation seems like the wrong direction. |
Sorry to be a bit negative here. But I don't really see a way to fix this entirely. There simply is too much state and edge cases going on, at least for me. The way I see it we have the following options:
Given that 3. could take a while, I think in the short-medium term we need to do either 1 or 2. I'm fine with either.
As far as I can see, it has been subtly broken since at least 1.x (haven't checked further back). It's still "undestroying" even if it's inline. Depending on when exactly you call |
I don't recall any bug reports so perhaps it works well enough in practice. If you think it's inherently unfixable (I don't necessarily disagree) then documenting the caveats is a good idea. |
I don't know what the exact caveats are. As far as I'm aware it's undefined behavior. So basically the documentation would be "here be dragons". The problem here is that there can be pending events from either IO or I'm not even sure what the user would expect in terms of behavior when I guess what I'm trying to say here is, we know it's broken, but not exactly how, we don't know the exact semantics of how we would like it to behave and it's difficult to fix so that it "reasonably" works. |
I think the question here is; what should we do with an API we know (at least I'm personally convinced) is broken and we are unlikely to fix (at least I'm personally sceptical). Maybe I'm a bit ahead of things and there is someone that thinks they can reasonably (whatever that means) fix it within an acceptable (whatever that means) timeframe? It's been broken for a very long time so I guess there is no hurry. On the other hand I'm personally not comfortable leaving it broken without telling our users. |
We can document that reusing a socket after it has been closed is not safe instead of deprecating const socket = new Socket(options);
socket.connect(); instead of const socket = net.connect(options); which does the same thing and still uses |
I'm fine with this. EDIT: Though I would like to be able to sometime in the future throw when called for re-use. |
This reverts commit 76bf3dd.
@lpinca: PTAL and see if you agree with the current wording. |
2071fb9
to
b4c24ef
Compare
If a user waits for |
In theory yes. In practice, not necessarily.
EDIT: #33204 (comment) |
I would be fine with changing the wording to " |
Can you show an example of this? |
Sorry, I got confused by #33137 which is actually another issue. |
I personally would prefer the more limited and informative description in #33204 (comment), so people understand under what circumstances they are really asking for trouble, and what should work. Perhaps not the place to discuss, but if calling .connect() on a currently connected and active socket is particularly dangerous, I think its worth considering whether that very specific use could be deprecated, even runtime deprecated. That would require that it is possible to know that the socket is not in a quiescent and disconnected state. If that is possible, perhaps issuing a run-time warning that the use is not safe would be reasonable. I suspect that people are not regularly doing the unsafe connect, we'd be flooded with bug reports. <-- just a thought, an aside from this documentation here. |
0382a34
to
3d26329
Compare
@sam-github updated wording PTAL |
3d26329
to
74430ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Landed in e50ae7a |
PR-URL: #33204 Refs: #25969 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
PR-URL: #33204 Refs: #25969 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
PR-URL: #33204 Refs: #25969 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
socket.connect
is subtly broken due to timing and _undestroy issues. Discourage usage and ask users to instead create a new socket instance.Note, this is a problem when calling
connect
a second time.I believe since it's a bit tricky to resolve, it might be appropriate to deprecate this use case since there is a viable alternative in simply creating a new socket.
Refs: #25969
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes