Uh oh!
There was an error while loading. Please reload this page.
net: emit 'close' after 'end' - #19241
Conversation
lpinca
commented
Mar 8, 2018
This is potentially semver-major as the |
addaleax
commented
Mar 8, 2018
This aligns behavior with other Will take a closer look tomorrow |
lpinca
commented
Mar 8, 2018
Yes, at least it aims to do that. |
mcollina
commented
Mar 8, 2018
I think this is semver-major. |
51636f4 to
9c58febCompareCI: https://ci.nodejs.org/job/node-test-pull-request/13601/ |
lpinca
commented
Mar 9, 2018
addaleax
commented
Mar 9, 2018
59e5611 to
6cfc5c8Comparemcollina
commented
Mar 12, 2018
@lpinca can you please check that we follow this pattern also in HTTP, HTTP2, fs, etc? Also, |
lpinca
commented
Mar 12, 2018
This is not trivial, it seems to be the case for HTTP but not fs, the
|
mcollina
commented
Mar 12, 2018
@lpinca |
addaleax
commented
Mar 12, 2018
For HTTP/2, |
@mcollina ok, I'll
|
I'm a bit hesitant on adding it to CITGM as it seems to be only tested with |
lpinca
commented
Mar 12, 2018
cc: @mafintosh |
6cfc5c8 to
590abf7CompareI would like to land this. It already has 3 TSC approvals but it would be nice to have more opinions. CI: https://ci.nodejs.org/job/node-test-pull-request/13738/ |
benjamingr
left a comment
There was a problem hiding this comment.
Definitely semver-major, changes lgtm
Currently the writable side of the socket is closed as soon as `UV_EOF` is read regardless of the state of the socket. This allows the handle to be closed before `'end'` is emitted and thus `'close'` can be emitted before `'end'` if the socket is paused. This commit prevents the handle from being closed until `'end'` is emitted ensuring the correct order of events. Fixes: nodejs#19166
Wait for the sockets to be connected before closing them and remove unneeded `setTimeout()`.
590abf7 to
5b957e1Comparelpinca
commented
Mar 21, 2018
lpinca
commented
Mar 21, 2018
Landed in 0ac4ef9...9b7a691. |
Wait for the sockets to be connected before closing them and remove unneeded `setTimeout()`. PR-URL: #19241 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Currently the writable side of the socket is closed as soon as `UV_EOF` is read regardless of the state of the socket. This allows the handle to be closed before `'end'` is emitted and thus `'close'` can be emitted before `'end'` if the socket is paused. This commit prevents the handle from being closed until `'end'` is emitted ensuring the correct order of events. PR-URL: #19241Fixes: #19166 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@lpinca On redis/ioredis#633 I'm seeing that the socket is not in a paused state (that is, its isPaused() returns false) but does have a If the answer is that this is not an intentional new behavior, I'll try to boil it down to more minimal repro case (one that doesn't involve spinning up a Redis cluster). |
lpinca
commented
Jun 10, 2018
If the socket is still writable it's expected, |
brettkiefer
commented
Jun 11, 2018
@lpinca Ok, thanks! It looks like what is happening here is that when we connect with a timeout that fires off an
So that causes the socket to never call Does that make sense to you? It may be that I have an incorrect expectation that calling |
lpinca
commented
Jun 11, 2018
@brettkiefer yes it makes sense, this is an interesting race condition. A dirty workaround would be to call |
brettkiefer
commented
Jun 11, 2018
@lpinca Thanks. that sounds like a good idea. I'll see what IORedis might accept as a workaround and get an issue submitted against Node.js tomorrow (unless you think you can give better context, in which case please feel free) and link it here. I don't immediately see any internal state on the socket that looks appropriate for switching behavior in |
lpinca
commented
Jun 11, 2018
Here is a test case for the issue you are describing: constnet=require('net');constserver=net.createServer();server.listen(()=>{constsocket=net.createConnection(server.address().port);socket.on('connect',()=>console.log('connect'));socket.on('end',()=>console.log('end'));socket.on('close',()=>console.log('close'));socket.end();});No |
Currently the writable side of the socket is closed as soon as
UV_EOFis read regardless of the state of the socket. This allows the handle
to be closed before
'end'is emitted and thus'close'can beemitted before
'end'if the socket is paused.This commit prevents the handle from being closed until
'end'isemitted ensuring the correct order of events.
Fixes: #19166
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes