From 715ab343bf319e56c9544906ec67d9d4e29feac7 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 11 Sep 2021 02:43:42 +0200 Subject: [PATCH] Explicitly drop events events to the master if no session exists Since the connector refactor the action of sending a message on a connector that is in the process of connecting changed from queuing up the message to send it to throwing an error. To avoid events forwarded by the slave to to the master when the connection is down from being logged as an error forwardEventToMaster has to explicitly drop them. --- packages/lib/link/connectors.js | 8 ++++++++ packages/slave/slave.js | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/packages/lib/link/connectors.js b/packages/lib/link/connectors.js index 3ae4235b..e2aacdf7 100644 --- a/packages/lib/link/connectors.js +++ b/packages/lib/link/connectors.js @@ -163,6 +163,14 @@ class WebSocketBaseConnector extends events.EventEmitter { get closing() { return this._closing || this._state === "closed"; } + + /** + * True if the connector currently has a valid session that is either + * connected or in the process of resuming. + */ + get hasSession() { + return ["connected", "resuming"].includes(this._state); + } } /** diff --git a/packages/slave/slave.js b/packages/slave/slave.js index 5d03bc63..ecc492ed 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -945,6 +945,10 @@ class InstanceConnection extends libLink.Link { } async forwardEventToMaster(message, event) { + if (!this.slave.connector.hasSession) { + return; + } + event.send(this.slave, message.data); }