From: Jérôme Benoit Date: Sat, 18 Sep 2021 11:38:40 +0000 (+0200) Subject: Factor out reconnection timeout calculation X-Git-Tag: v1.1.4~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a0f59b75d0a6fbb8c91feee03a2fb4c0e5d3b3c4;p=e-mobility-charging-stations-simulator.git Factor out reconnection timeout calculation Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 35bbdd49..9cb5e066 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1050,10 +1050,11 @@ export default class ChargingStation { if (this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries() || this.getAutoReconnectMaxRetries() === -1) { this.autoReconnectRetryCount++; const reconnectDelay = (this.getReconnectExponentialDelay() ? Utils.exponentialDelay(this.autoReconnectRetryCount) : this.getConnectionTimeout() * 1000); - logger.error(`${this.logPrefix()} Socket: connection retry in ${Utils.roundTo(reconnectDelay, 2)}ms, timeout ${reconnectDelay - 100}ms`); + const reconnectTimeout = reconnectDelay - 100; + logger.error(`${this.logPrefix()} Socket: connection retry in ${Utils.roundTo(reconnectDelay, 2)}ms, timeout ${reconnectTimeout}ms`); await Utils.sleep(reconnectDelay); logger.error(this.logPrefix() + ' Socket: reconnecting try #' + this.autoReconnectRetryCount.toString()); - this.openWSConnection({ handshakeTimeout: reconnectDelay - 100 }, true); + this.openWSConnection({ handshakeTimeout: reconnectTimeout }, true); this.hasSocketRestarted = true; } else if (this.getAutoReconnectMaxRetries() !== -1) { logger.error(`${this.logPrefix()} Socket reconnect failure: max retries reached (${this.autoReconnectRetryCount}) or retry disabled (${this.getAutoReconnectMaxRetries()})`);