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

Cluster 2.0 - step 6 : Add disconnect methods to graceful shutdown #2740

Closed
wants to merge 1 commit into from

Conversation

AndreasMadsen
Copy link
Member

It is important that a worker can die graceful so no connected clients are interrupted. This patch adds:

  • worker.disconnect() stop server from accepting new connections, and close the IPC channel when all connection are ended. The documentation include an example on how to make a timeout.
  • cluster.disconnect() run worker.disconnect() and all living workers and then close the handlers create in master allowing the cluster to die graceful.
  • worker.on('disconnect') emits when IPC channel is closed.
  • cluster.on('disconnect') same as worker.on('disconnect') just global this follow the existing pattern.

There was an related issue to this: #2088

This is about the merging in the good parts from the cluster 2.0 ( see #2038 ) pull request

@AndreasMadsen
Copy link
Member Author

I'm afraide this this need a better testcase.

@AndreasMadsen
Copy link
Member Author

@isaacs this is ready for review and thoughts

@AndreasMadsen
Copy link
Member Author

Another approach to cluster.disconnect() graceful kill the cluster would be to make a cluster.close() function there will simply close all handlers when all workers are disconnected. The difference is that userland will need to manually call worker.disconnect() on all workers. This is much like the net.Server.close() where userland will need to end all connections before the server handler is closed.

However net.Server.close() do also stop the server from accepting new connections, if cluster.close() should do that too there wouldn't be any difference between cluster.disconnect() and cluster.close().

Somehow I needed to write this message too conclude that cluster.disconnect() is the best approach.

@AndreasMadsen
Copy link
Member Author

@isaacs I have now rebased onto master and resolved all conflicts, the commits has also been squashed.

This patch add a worker.disconnect() method there will stop the worker from accepting
new connections and then stop the IPC. This allow the worker to die graceful.
When the IPC has been disconnected a 'disconnect' event will emit.

The patch also add a cluster.disconnect() method, this will call worker.disconnect() on
all connected workers. When the workers are disconneted it will then close all server
handlers. This allow the cluster itself to self terminate in a graceful way.
@isaacs
Copy link

isaacs commented Mar 19, 2012

Landed on master. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants