Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

net: allow cluster workers to listen on exclusive ports #8238

Closed
wants to merge 8 commits into from
Closed

net: allow cluster workers to listen on exclusive ports #8238

wants to merge 8 commits into from

Conversation

cjihrig
Copy link

@cjihrig cjihrig commented Aug 22, 2014

Currently, all listen() calls go through the cluster master. This commit allows workers to listen on ports exclusively. Closes #3856

Currently, all listen() calls go through the cluster master.
This commit allows workers to listen on ports exclusively.
Closes #3856
@Fishrock123
Copy link

Yes please. Hoping this can land in 0.12. Dx

function listen(self, address, port, addressType, backlog, fd) {
function listen(self, address, port, addressType, backlog, fd, shared) {
// listening still goes through master by default
shared = shared === undefined ? true : !!shared;
Copy link
Member

Choose a reason for hiding this comment

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

May be shared !== false ?

@indutny
Copy link
Member

indutny commented Aug 27, 2014

LGTM, please fix minor nits. Thank you!

@cjihrig
Copy link
Author

cjihrig commented Aug 27, 2014

@indutny I've addressed your comments. Thanks.

server.listen({
host: 'localhost',
port: 80,
shared: true

Choose a reason for hiding this comment

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

shared: false?

@sam-github
Copy link

Could you apply also to dgram? We can't actually use dgram on windows right now in cluster workers, but if we could specify shared, we could.

@sam-github
Copy link

Also, this doesn't fix for local domain sockets, either, does it? You can't do server.listen({path: ..., shared: false})? Or do I misremember, and local domain stream sockets (or windows named pipes) aren't shared among cluster workers?

function listen(self, address, port, addressType, backlog, fd) {
function listen(self, address, port, addressType, backlog, fd, shared) {
// listening still goes through master by default
shared = shared !== false;

Choose a reason for hiding this comment

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

You consider 0, null, and undefined to be true? I think this is weird. I suggest that this should be shared = !!shared

Copy link
Author

Choose a reason for hiding this comment

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

I originally had:

shared = shared === undefined ? true : !!shared;

I was asked to change it. undefined is a bit of a special case because the shared argument is not always passed, but shared should default to true. I think the simplest solution would be to explicitly pass all arguments, which is achievable since this is an internal API.

EDIT: I responded to this before reading your next comment. It may be simpler to switch to from shared to exclusive.

@sam-github
Copy link

I like this, and to see it consistently applied to all the sockets that cluster shares, not just tcp.

Currently, all dgram bind() calls go through the cluster
master. This commit allows workers to bind to a port
exclusively.
@cjihrig
Copy link
Author

cjihrig commented Aug 29, 2014

@sam-github updated with support for dgram and socket paths.

There is one case that is still not covered - listening on an existing handle/fd. Adding support wouldn't be too hard. The biggest problem is what to call the property. I can't use handle, because it's currently used for argument parsing. Also not sure that it makes sense to support this use case, as the point of the exclusive option is to get a new handle.

@trevnorris trevnorris added the net label Sep 3, 2014
@@ -152,6 +152,7 @@ function replaceHandle(self, newHandle) {

Socket.prototype.bind = function(/*port, address, callback*/) {
var self = this;
var firstArg = arguments[0];

Choose a reason for hiding this comment

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

If this is immediately being set, why not just place it in the argument declaration?

@cjihrig
Copy link
Author

cjihrig commented Sep 3, 2014

@trevnorris I have addressed your comments.

* `callback` {Function} - Optional.

The `port`, `host`, and `backlog` properties of `options`, as well as the
optional callback function, behave as they do on a call to

Choose a reason for hiding this comment

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

trailing whitespace

@cjihrig
Copy link
Author

cjihrig commented Sep 3, 2014

@trevnorris - updated

@trevnorris
Copy link

Thanks. Squashed, slightly re-worded and landed in 029cfc1.

@trevnorris trevnorris closed this Sep 3, 2014
@cjihrig cjihrig deleted the 3856 branch September 3, 2014 22:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants