From: Jérôme Benoit Date: Thu, 26 May 2022 20:33:59 +0000 (+0200) Subject: Fix WS reconnect timeout calculation X-Git-Tag: v1.1.61~27 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1e080116b0b62d897258a28efa129a9a65bf7d4e;p=e-mobility-charging-stations-simulator.git Fix WS reconnect timeout calculation Signed-off-by: Jérôme Benoit --- diff --git a/package-lock.json b/package-lock.json index f258bf73..f1078310 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "uuid": "^8.3.2", "winston": "^3.7.2", "winston-daily-rotate-file": "^4.6.1", - "ws": "^8.6.0" + "ws": "^8.7.0" }, "devDependencies": { "@istanbuljs/nyc-config-typescript": "^1.0.2", @@ -405,7 +405,7 @@ "node_modules/@babel/highlight/node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "node_modules/@babel/highlight/node_modules/escape-string-regexp": { @@ -4014,7 +4014,7 @@ "node_modules/color/node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" }, "node_modules/colorette": { "version": "2.0.16", @@ -7828,7 +7828,7 @@ "node_modules/inquirer/node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "node_modules/inquirer/node_modules/escape-string-regexp": { @@ -8019,7 +8019,7 @@ "node_modules/insight/node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "node_modules/insight/node_modules/escape-string-regexp": { @@ -14678,7 +14678,7 @@ "node_modules/showdown/node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "node_modules/showdown/node_modules/emoji-regex": { @@ -16960,9 +16960,9 @@ } }, "node_modules/ws": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", - "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.7.0.tgz", + "integrity": "sha512-c2gsP0PRwcLFzUiA8Mkr37/MI7ilIlHQxaEAtd0uNMbVMoy8puJyafRlm0bV9MbGSabUPeLrRRaqIBcFcA2Pqg==", "engines": { "node": ">=10.0.0" }, @@ -17536,7 +17536,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "escape-string-regexp": { @@ -20314,7 +20314,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" } } }, @@ -23455,7 +23455,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "escape-string-regexp": { @@ -23613,7 +23613,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "escape-string-regexp": { @@ -28695,7 +28695,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "emoji-regex": { @@ -30519,9 +30519,9 @@ } }, "ws": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", - "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.7.0.tgz", + "integrity": "sha512-c2gsP0PRwcLFzUiA8Mkr37/MI7ilIlHQxaEAtd0uNMbVMoy8puJyafRlm0bV9MbGSabUPeLrRRaqIBcFcA2Pqg==", "requires": {} }, "xdg-basedir": { diff --git a/package.json b/package.json index db6cf1b2..617b41df 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "uuid": "^8.3.2", "winston": "^3.7.2", "winston-daily-rotate-file": "^4.6.1", - "ws": "^8.6.0" + "ws": "^8.7.0" }, "optionalDependencies": { "bufferutil": "^4.0.6", diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 6e9a0d87..4e9abedf 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1879,18 +1879,26 @@ export default class ChargingStation { private openWSConnection( options: WsOptions = this.stationInfo?.wsOptions ?? {}, - forceCloseOpened = false + params: { closeOpened?: boolean; terminateOpened?: boolean } = { + closeOpened: false, + terminateOpened: false, + } ): void { options.handshakeTimeout = options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000; + params.closeOpened = params?.closeOpened ?? false; + params.terminateOpened = params?.closeOpened ?? false; if ( !Utils.isNullOrUndefined(this.stationInfo.supervisionUser) && !Utils.isNullOrUndefined(this.stationInfo.supervisionPassword) ) { options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`; } - if (this.isWebSocketConnectionOpened() && forceCloseOpened) { + if (this.isWebSocketConnectionOpened() && params?.closeOpened) { this.wsConnection.close(); } + if (this.isWebSocketConnectionOpened() && params?.terminateOpened) { + this.wsConnection.terminate(); + } let protocol: string; switch (this.getOcppVersion()) { case OCPPVersion.VERSION_16: @@ -1935,7 +1943,11 @@ export default class ChargingStation { const reconnectDelay = this.getReconnectExponentialDelay() ? Utils.exponentialDelay(this.autoReconnectRetryCount) : this.getConnectionTimeout() * 1000; - const reconnectTimeout = reconnectDelay - 100 > 0 && reconnectDelay; + const reconnectDelayWithdraw = 1000; + const reconnectTimeout = + reconnectDelay && reconnectDelay - reconnectDelayWithdraw > 0 + ? reconnectDelay - reconnectDelayWithdraw + : 0; logger.error( `${this.logPrefix()} WebSocket: connection retry in ${Utils.roundTo( reconnectDelay, @@ -1950,7 +1962,7 @@ export default class ChargingStation { ); this.openWSConnection( { ...(this.stationInfo?.wsOptions ?? {}), handshakeTimeout: reconnectTimeout }, - true + { closeOpened: true } ); this.wsConnectionRestarted = true; } else if (this.getAutoReconnectMaxRetries() !== -1) { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index d3128469..e31d9b25 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -96,6 +96,8 @@ export default class Constants { 'configurationHash', ]); + static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = Number.MAX_SAFE_INTEGER; + static readonly DEFAULT_HASH_ALGORITHM = 'sha384'; static readonly DEFAULT_IDTAG = '00000000';