diff --git a/clusterctl.js b/clusterctl.js index f3e22c67..79d9a6b9 100644 --- a/clusterctl.js +++ b/clusterctl.js @@ -353,7 +353,7 @@ class Control extends link.Link { } async shutdown() { - await link.messages.shutdownConnection.send(this); + await link.messages.prepareDisconnect.send(this); this.connector.close(1001, "Control Quit") await events.once(this.connector, "close"); } diff --git a/docs/socket.md b/docs/socket.md index 597ef535..87d4718a 100644 --- a/docs/socket.md +++ b/docs/socket.md @@ -253,28 +253,29 @@ requests and their contents. - error - string - Human readable text message describing the error. -Graceful shutdown ------------------ +Graceful Disconnect +------------------- To ensure no data is lost when closing the link it's important to -send connection shutdown request and wait for it to complete before +send a prepare disconnect request and wait for it to complete before closing the WebSocket. Either party of the link can send this request and the party sending the request should be the one that initates the close of the WebSocket. -### `connection_shutdown_request` +### `prepare_disconnect_request` -Request graceful shutdown of the connection. The receiving party should +Request graceful disconnect of the connection. The receiving party should stop tasks that send events and requests over the link and wait for pending requests it has over the link to complete, but it should not stop responding to requests sent to it. Only after this process is done should the response be sent. -### `connection_shutdown_response` +### `prepare_disconnect_response` -Signals the shutdown is complete and that the connection can be closed. -The party that initiatied the shutdown request may still send other -requests/events over the link to finish its part of the shutdown. +Signals the preparation for disconnect is complete and that the +connection can be closed. The party that initiatied the prepare +disconnect request may still send other requests/events over the link to +finish its part of the disconnection proceedure. If the error response variant is received it should be logged if possible and treated as a success. diff --git a/lib/link/link.js b/lib/link/link.js index 20377652..f55087ba 100644 --- a/lib/link/link.js +++ b/lib/link/link.js @@ -208,14 +208,14 @@ class Link { async pingRequestHandler() { } /** - * Prepare connection for close + * Prepare connection for disconnect * * Waits for all pending requests on the connection to resolve. * Sub-classes should implement this handler with code that prevents * additional requests to be sent out before calling the super class * method. */ - async shutdownConnectionRequestHandler() { + async prepareDisconnectRequestHandler() { let promises = []; for (let waiterType of this._waiters.values()) { for (let waiter of waiterType) { diff --git a/lib/link/messages.js b/lib/link/messages.js index dc34b1a0..97044ced 100644 --- a/lib/link/messages.js +++ b/lib/link/messages.js @@ -185,8 +185,8 @@ let messages = {} // Connection requests let wsLinks = ["master-control", "control-master", "master-slave", "slave-master"]; -messages.shutdownConnection = new Request({ - type: "shutdown_connection", +messages.prepareDisconnect = new Request({ + type: "prepare_disconnect", links: wsLinks, }); diff --git a/master.js b/master.js index 876d9bac..62381061 100644 --- a/master.js +++ b/master.js @@ -381,7 +381,7 @@ class BaseConnection extends link.Link { } async shutdown(code, reason) { - await link.messages.shutdownConnection.send(this); + await link.messages.prepareDisconnect.send(this); this.connector.close(code, reason); await events.once(this.connector, "close"); } diff --git a/slave.js b/slave.js index 0940fb6c..18ed831c 100644 --- a/slave.js +++ b/slave.js @@ -740,7 +740,7 @@ class Slave extends link.Link { } async shutdown() { - await link.messages.shutdownConnection.send(this); + await link.messages.prepareDisconnect.send(this); for (let instanceId of this.instanceConnections.keys()) { await this.stopInstance(instanceId); } diff --git a/test/integration/link.js b/test/integration/link.js index f1b1dba5..d684b09e 100644 --- a/test/integration/link.js +++ b/test/integration/link.js @@ -12,7 +12,7 @@ class TestControl extends link.Link { link.attachAllMessages(this); } - async shutdownConnectionRequestHandler() { } + async prepareDisconnectRequestHandler() { } async instanceOutputEventHandler() { } }