- Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
JS SignalR Client version: 6.0.7
/** The version of the SignalR client. */ const VERSION = "6.0.7"; Overview.
Using standard SignalR reconnection mechanism, and in case connection was not finally established, the number of reconnection attempts is incorrectly logged. The number is -> reconnection attempts + 1, but expected to be -> reconnection attempts.
Details.
source: HubConnection.ts
method: private async _reconnect(error?: Error)
Problematic code-snippet _reconnect() loop source:
while (nextRetryDelay !== null) { this._logger.log(LogLevel.Information, `Reconnect attempt number ${previousReconnectAttempts} will start in ${nextRetryDelay} ms.`); //... try { await this._startInternal(); // ... return; } catch (e) { this._logger.log(LogLevel.Information, `Reconnect attempt failed because of error '${e}'.`); // ... retryError = e instanceof Error ? e : new Error(e.toString()); // ! source code line number 822, previousReconnectAttempts++ // increment, which finally influence on the incorrect log message (in case connection was not established). nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, Date.now() - reconnectStartTime, retryError); } } // ! source code line number 826 // incorrect number of reconnection attempts logged. this._logger.log(LogLevel.Information, `Reconnect retries have been exhausted after ${Date.now() - reconnectStartTime} ms and ${previousReconnectAttempts} failed attempts. Connection disconnecting.`); this._completeClose(); source line 822:
nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, Date.now() - reconnectStartTime, retryError);
source line 826:
this._logger.log(LogLevel.Information, `Reconnect retries have been exhausted after ${Date.now() - reconnectStartTime} ms and ${previousReconnectAttempts} failed attempts. Connection disconnecting.`);
Issue example.
When standard .withAutomaticReconnect() (witch attempts to reconnect 4 times [0, 2000, 10000, 30000]) fails to reconnect the following log message is logged:
[2022-07-19T07:55:10.103Z] Information: Reconnect retries have been exhausted after 58811 ms and 5 failed attempts. Connection disconnecting. Message contains 5 attempts, but actually there were 4 attempts.
Expected Behavior
In case reconnection fails to establish connection, then the number of attempts logged should correspond to the number of actual reconnection attempts.
Steps To Reproduce
- Create connection and start it.
const hubConnection = new signalR.HubConnectionBuilder() .withUrl("<connectionURL>") .withAutomaticReconnect() .configureLogging(signalR.LogLevel.Information); hubConnection.start(); -
Stop hub, interrupting (closing) connection.
-
Check log messages.
Example:
[2022-07-19T07:54:11.293Z] Information: Reconnect attempt number 1 will start in 0 ms. [2022-07-19T07:54:15.388Z] Information: Reconnect attempt failed because of error 'Error: Failed to complete negotiation with the server: TypeError: Failed to fetch'. [2022-07-19T07:54:15.388Z] Information: Reconnect attempt number 2 will start in 2000 ms. [2022-07-19T07:54:21.464Z] Warning: Error from HTTP request. TypeError: Failed to fetch. [2022-07-19T07:54:21.465Z] Information: Reconnect attempt failed because of error 'Error: Failed to complete negotiation with the server: TypeError: Failed to fetch'. [2022-07-19T07:54:21.465Z] Information: Reconnect attempt number 3 will start in 10000 ms. [2022-07-19T07:54:35.575Z] Warning: Error from HTTP request. TypeError: Failed to fetch. [2022-07-19T07:54:35.576Z] Information: Reconnect attempt failed because of error 'Error: Failed to complete negotiation with the server: TypeError: Failed to fetch'. [2022-07-19T07:54:35.576Z] Information: Reconnect attempt number 4 will start in 30000 ms. [2022-07-19T07:55:10.102Z] Warning: Error from HTTP request. TypeError: Failed to fetch. [2022-07-19T07:55:10.103Z] Information: Reconnect attempt failed because of error 'Error: Failed to complete negotiation with the server: TypeError: Failed to fetch'. [2022-07-19T07:55:10.103Z] Information: Reconnect retries have been exhausted after 58811 ms and 5 failed attempts. Connection disconnecting. There were 4 actual attempts to reconnect. Logged 5 attempts -> "Reconnect retries have been exhausted after 58811 ms and 5 failed attempts."
Exceptions (if any)
No response
.NET Version
6.0.300
Anything else?
No response