-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Provide an easy way to get all net.Server connections #48433
Comments
A similar feature was originally proposed in #42812, but I consider it an anti-pattern in Node.js (see #42812 (review)):
|
Another reason not to do this is that it would be incongruent with 1 Which, for the record, I think is of questionable design too. |
Honestly I can't imagine what current getConnections() could be useful for at all. Anyway everyone has to implement the list of connected sockets manually to be able to close the server fully. If an app serves millions of clients, the list would only occupy several MBs in memory which is nothing compared to all the allocated socket objects. Probably it's the lookups in containers with millions of items that are problem? |
@tniessen @bnoordhuis If it weren't for
Especially @bnoordhuis said "such connections are gone", although I don't get why. If some connections are gone, what is the point of using count in its callback? |
I assume And I believe what @bnoordhuis meant is that the primary process in a cluster does not have access to all connection objects because some exist in the address space / JS heap of other processes. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
What is the problem this feature will solve?
Currently, there seems no way to get all
net.Server
connections with the public API.net.server.getConnections((err, count) => {...})
only returns the count of the connection, I can't get each connection within its callback. I triedfor (let socket of server.connections) {...}
inside the callback, and got the error TypeError: server.connections is not iterable.I have to store each socket myself on
Event: 'connection'
callback, keep an array of those socket objects.What is the feature you are proposing to solve the problem?
Inside
net.server.getConnections((err, count) => {...})
callback, in addition to returning connection count, also return all the connections.What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: