Emit resume instead of connect on resumed connections

Raise "resume" instead of "connect" when a connection is re-established
after a connection drop.  This prevents logic meant to resynchronize
state after a full reconnection from being invoked whenever the
connection was temporarily dropped.
This commit is contained in:
Hornwitser committed 2021-02-19 14:28:19 +01:00
1 parent b4cbe2355d
commit 1de8b76303
6 files changed
+26 -18

No files matched your search

+1 -1
View File
@@ -621,7 +621,7 @@ until the connection is re-established. This means that if your plugin
sends a lot of events or requests, they can end up being queued up in a sends a lot of events or requests, they can end up being queued up in a
buffer for a long time and sent out all at once. To avoid this you buffer for a long time and sent out all at once. To avoid this you
should be throtteling and/or stopping your requests/events after `drop` should be throtteling and/or stopping your requests/events after `drop`
has been raised, and continue back as normal when `connect` is raised. has been raised, and continue back as normal when `resume` is raised.
Collecting Statistics Collecting Statistics
+1 -1
View File
@@ -404,7 +404,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
} }
this._startedReconnect = null; this._startedReconnect = null;
this._connected = true; this._connected = true;
this.emit("connect"); this.emit("resume");
} else if (type === "invalidate") { } else if (type === "invalidate") {
this._heartbeatInterval = null; this._heartbeatInterval = null;
+18 -10
View File
@@ -148,13 +148,12 @@ class BaseInstancePlugin {
/** /**
* Called when an event on the master connection happens * Called when an event on the master connection happens
* *
* The event param may be one of connect, drop and close and has the * The event param may be one of connect, drop, resume and close and has
* following meaning: * the following meaning:
* *
* ##### connect * ##### connect
* *
* Invoked when a new connection to the master has been established, or * Invoked when a new connection to the master has been established.
* the existing one that have previously been dropped is re-established.
* *
* ##### drop * ##### drop
* *
@@ -166,6 +165,11 @@ class BaseInstancePlugin {
* memory on the slave and sent all in one go when the connection is * memory on the slave and sent all in one go when the connection is
* re-established again. * re-established again.
* *
* ##### resume
*
* Invoked when the connection that had previously dropped is
* re-established.
*
* ##### close * ##### close
* *
* Invoked when the connection to the master has been closed. This * Invoked when the connection to the master has been closed. This
@@ -173,7 +177,7 @@ class BaseInstancePlugin {
* send any messages that goes to or via the master server after the * send any messages that goes to or via the master server after the
* connection has been closed and before a new one is established. * connection has been closed and before a new one is established.
* *
* @param {string} event - one of connect, drop, and close * @param {string} event - one of connect, drop, resumeand close
*/ */
onMasterConnectionEvent(event) { } onMasterConnectionEvent(event) { }
@@ -293,13 +297,12 @@ class BaseMasterPlugin {
/** /**
* Called when an event on a slave connection happens * Called when an event on a slave connection happens
* *
* The event param may be one of connect, drop and close and has the * The event param may be one of connect, drop, resume and close and has
* following meaning: * the following meaning:
* *
* ##### connect * ##### connect
* *
* Invoked when a new connection to the slave has been established, or * Invoked when a new connection to the slave has been established.
* an existing one that had previously been dropped is re-established.
* *
* ##### drop * ##### drop
* *
@@ -311,13 +314,18 @@ class BaseMasterPlugin {
* memory on the master and sent all in one go when the connection is * memory on the master and sent all in one go when the connection is
* re-established again. * re-established again.
* *
* ##### resume
*
* Invoked when a connection that had previously been dropped is
* re-established
*
* ##### close * ##### close
* *
* Invoked when the connection to the slave has been closed. * Invoked when the connection to the slave has been closed.
* *
* @param {module:master/master~SlaveConnection} connection - * @param {module:master/master~SlaveConnection} connection -
* The connection the event occured on. * The connection the event occured on.
* @param {string} event - one of connect, drop, and close * @param {string} event - one of connect, drop, resume and close
*/ */
onSlaveConnectionEvent(connection, event) { } onSlaveConnectionEvent(connection, event) { }
+2 -2
View File
@@ -1168,7 +1168,7 @@ class SlaveConnection extends BaseConnection {
} }
}); });
for (let event of ["connect", "drop", "close"]) { for (let event of ["connect", "drop", "resume", "close"]) {
// eslint-disable-next-line no-loop-func // eslint-disable-next-line no-loop-func
this.connector.on(event, () => { this.connector.on(event, () => {
for (let masterPlugin of masterPlugins.values()) { for (let masterPlugin of masterPlugins.values()) {
@@ -1397,7 +1397,7 @@ class WebSocketServerConnector extends libLink.WebSocketBaseConnector {
for (let message of this._sendBuffer) { for (let message of this._sendBuffer) {
this._socket.send(JSON.stringify(message)); this._socket.send(JSON.stringify(message));
} }
this.emit("connect"); this.emit("resume");
} }
setTimeout(timeout) { setTimeout(timeout) {
+1 -1
View File
@@ -1028,7 +1028,7 @@ class Slave extends libLink.Link {
} }
}); });
for (let event of ["connect", "drop", "close"]) { for (let event of ["connect", "drop", "resume", "close"]) {
this.connector.on(event, () => { this.connector.on(event, () => {
for (let instanceConnection of this.instanceConnections.values()) { for (let instanceConnection of this.instanceConnections.values()) {
libLink.messages.masterConnectionEvent.send(instanceConnection, { event }); libLink.messages.masterConnectionEvent.send(instanceConnection, { event });
+3 -3
View File
@@ -34,17 +34,17 @@ describe("Integration of lib/link", function() {
it("should reconnect on connection lost", async function() { it("should reconnect on connection lost", async function() {
controlConnector._socket.close(1008, "Test"); controlConnector._socket.close(1008, "Test");
await events.once(controlConnector, "connect"); await events.once(controlConnector, "resume");
}); });
it("should reconnect on connection terminated", async function() { it("should reconnect on connection terminated", async function() {
controlConnector._socket.terminate(); controlConnector._socket.terminate();
await events.once(controlConnector, "connect"); await events.once(controlConnector, "resume");
}); });
it("should reconnect on connection heartbeat timeout", async function() { it("should reconnect on connection heartbeat timeout", async function() {
controlConnector.stopHeartbeat(); controlConnector.stopHeartbeat();
await events.once(controlConnector, "connect"); await events.once(controlConnector, "resume");
}); });
it("should invalidate on reconnection with bad session token", async function() { it("should invalidate on reconnection with bad session token", async function() {