From 85a984734b1f4817f50d11eaf8a539151e2cd1a6 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 6 Mar 2021 18:14:39 +0100 Subject: [PATCH 1/3] Fix node-forge dependency The removal of the automatic TLS certificate generation removed the use of node-forge in the master server, while the addition of the HttpCloser added it as dependency of the tests. Fix node-forge dependency being listed in lib and master instead of as a dev dependency in package.json. --- package.json | 1 + packages/lib/package.json | 1 - packages/master/package.json | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 90523bb5..f7669f6a 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "jszip": "^3.2.2", "lerna": "^3.22.1", "mocha": "^6.2.0", + "node-forge": "^0.10.0", "nyc": "^14.1.1", "phin": "^3.4.1", "webpack": "^5.0.0" diff --git a/packages/lib/package.json b/packages/lib/package.json index ee27b199..58133a27 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -19,7 +19,6 @@ "jsonwebtoken": "^8.2.1", "jszip": "^3.2.2", "klaw": "^3.0.0", - "node-forge": "^0.10.0", "rcon-client": "^4.2.0", "semver": "^7.1.1", "set-blocking": "^2.0.0", diff --git a/packages/master/package.json b/packages/master/package.json index 81e3faf5..937d5f0a 100644 --- a/packages/master/package.json +++ b/packages/master/package.json @@ -29,7 +29,6 @@ "jsonwebtoken": "^8.2.1", "jszip": "^3.2.2", "node-factorio-api": "^0.3.8", - "node-forge": "^0.10.0", "set-blocking": "^2.0.0", "winston": "^3.3.3", "ws": "^7.2.3", From d6f09f4c1a41aac661612b4280759be6d2bfe82c Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 6 Mar 2021 18:29:31 +0100 Subject: [PATCH 2/3] Fix close during reconnect wait period If the connect close method is called while the connection is waiting for a reconnection attempt then the attempt is cancelled but the close method then erroneously waited for a close event that would never happen. Fix by resetting the connector and rasing the close event in the close method if it's in the waiting for reconnect state. --- packages/lib/link/connectors.js | 7 +++++++ test/integration/link.js | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/lib/link/connectors.js b/packages/lib/link/connectors.js index f3881d26..0932070f 100644 --- a/packages/lib/link/connectors.js +++ b/packages/lib/link/connectors.js @@ -211,6 +211,13 @@ class WebSocketClientConnector extends WebSocketBaseConnector { if (this._reconnectId) { clearTimeout(this._reconnectId); this._reconnectId = null; + this._lastReceivedSeq = null; + this._sessionToken = null; + this._sendBuffer.length = 0; + this._state = "new"; + this._connected = false; + this.emit("close"); + return; } this.stopHeartbeat(); diff --git a/test/integration/link.js b/test/integration/link.js index 39848e16..183147f6 100644 --- a/test/integration/link.js +++ b/test/integration/link.js @@ -53,4 +53,12 @@ describe("Integration of lib/link", function() { await events.once(controlConnector, "invalidate"); await events.once(controlConnector, "connect"); }); + + it("should properly close connector if close is called during reconnect wait", async function() { + controlConnector._socket.close(1008, "Test"); + controlConnector.once("drop", () => { + controlConnector.close(); + }); + await events.once(controlConnector, "close"); + }); }); From 2069689780fa7046d91190650381846d25cf52f0 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 6 Mar 2021 18:32:53 +0100 Subject: [PATCH 3/3] Remove --exit flag from tests When setting up the tests there were issues with code that didn't properly clean up after itself and left lingering connections, intervals or timers that kept the event loop running after the tests where done. To fix this the --exit flag was passed as a temporary measure but then subsequently forgotten about. The issues with keeping the event loop alive have long since been fixed on Linux, but on Windows there was a problem with the control connector not exiting because the master server was killed instead of shutten down properly. With that issue fixed there are no longer any connections or timers keeping the event loop alive and --exit can thus be removed. --- package.json | 2 +- test/integration/index.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f7669f6a..fadd435c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "root", "private": true, "scripts": { - "test": "mocha --exit --check-leaks -R spec --recursive test plugins/global_chat/test plugins/research_sync/test plugins/statistics_exporter/test plugins/subspace_storage/test", + "test": "mocha --check-leaks -R spec --recursive test plugins/global_chat/test plugins/research_sync/test plugins/statistics_exporter/test plugins/subspace_storage/test", "fast-test": "FAST_TEST=y npm test", "cover": "nyc npm test", "fast-cover": "FAST_TEST=y nyc npm test", diff --git a/test/integration/index.js b/test/integration/index.js index 59051a18..f3ab1e76 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -175,6 +175,7 @@ after(async function() { masterProcess.kill("SIGINT"); await events.once(masterProcess, "exit"); } + await control.connector.close(); }); // Ensure the test processes are stopped.