-
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
cluster: wait for all servers closing before disconnect #1400
Conversation
/cc @bnoordhuis |
// Wait for any data, then close connection | ||
socket.on('data', socket.end.bind(socket)); | ||
|
||
}).listen(common.PORT, '127.0.0.1'); |
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.
Could you change 127.0.0.1
to common.localhostIPv4
?
@brendanashworth done |
@@ -625,12 +625,26 @@ function workerInit() { | |||
|
|||
Worker.prototype.disconnect = function() { | |||
this.suicide = true; | |||
var waitingHandles = 0; | |||
|
|||
function check() { |
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.
Can you please use a more descriptive name. Maybe checkRemainingHandles
.
@cjihrig tests are the same, except scheduling policy. But there are note in the |
@cjihrig is this (still?) lgty? |
@Fishrock123 the code changes themselves look good to me. I don't love the tests. Seems like a single test should be adequate, and it would be nice to simplify the test a bit if possible. |
@cjihrig I think two tests are required to ensure both scheduling policies are working correct. |
I don't think the code being tested here is really reliant on the scheduling policy. Granted, the |
fwiw, I agree with @cjihrig about the tests. As far as this change goes, it looks OK to me, though I haven't run or tested it. In particular, it looks like the ProgressTracker was lost in the cluster rewrite: https://github.com/joyent/node/blob/v0.10.38-release/lib/cluster.js#L520-L528, and this PR brings something like it back. |
@sam-github @cjihrig now there are only one test. If it is ok now I'll do rebase/squash to a single commit. |
Please squash. I just ran the test _without_ your changes, and the test passes when it should not. Can you check this? |
Fix for iojs/io,js#1305 Before this, cluster bahaves not the way it is docummented Then disconnect is triggered, worker must wait for every server is closed before doing disconnect actually. See test case and discussion in the above mentioned issue
a923192
to
35854ae
Compare
@sam-github commits squashed, test fixed. |
}); | ||
|
||
process.once('exit', function() { | ||
assert.ok(checks.disconnectedOnClientsEnd, 'The worker disconnected before all clients are ended'); |
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.
run make lint
, this line is too long.
I would just do the lint fixups and merge, but I'd like you to confirm that I'm not missing some subtlety about the exit event testing. |
@sam-github Yes, exit event testing is not necessary. It is copy-paste from another cluster test ( |
Before this, cluster behaves not the way it is documented. When disconnect is triggered, worker must wait for every server is closed before doing disconnect actually. Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> PR-URL: nodejs#1400 Fixes: nodejs#1305
@sam-github I'm sorry, but tests now broken. First If I run the test without my fixes, it will run forever. But if I set scheduling policy to This is because of default Then scheduling policy is |
@sam-github I think this probably needed a CI run, you have access to the CI, right? Anyways, here's a run on current master: https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/788/ |
} | ||
process.disconnect(); | ||
|
||
if (waitingHandles === 0) { |
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.
Why is this block necessary? Won't checkRemainingHandles
itself handle this?
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.
What if we have no any handles yet?
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.
Cool. Thanks for clarifying :-)
Wait for data to arrive from worker before doing a disconnect. Without this, whether the disconnect arrives at the worker before the master accepts and forwards the connection descriptor to the worker is a race. Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: Rod Vagg <[email protected]> PR-URL: #1953 Fixes: #1933 Fixes: #1400
Fix for #1305
Before this, cluster bahaves not the way it is docummented
Then disconnect is triggered, worker must wait for every server is closed
before doing disconnect actually.
See test case and discussion in the above mentioned issue