Skip to content

Commit

Permalink
Fix websocket reconnection can get stuck in disconnected/connecting c…
Browse files Browse the repository at this point in the history
…ycle
  • Loading branch information
VeskeR committed Sep 6, 2024
1 parent ee76047 commit d65b03d
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/common/lib/transport/connectionmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,27 +1101,25 @@ class ConnectionManager extends EventEmitter {
'ConnectionManager WebSocket slow timer',
'checking connectivity',
);
if (this.wsCheckResult === null) {
this.checkWsConnectivity()
.then(() => {
Logger.logAction(
this.logger,
Logger.LOG_MINOR,
'ConnectionManager WebSocket slow timer',
'ws connectivity check succeeded',
);
this.wsCheckResult = true;
})
.catch(() => {
Logger.logAction(
this.logger,
Logger.LOG_MAJOR,
'ConnectionManager WebSocket slow timer',
'ws connectivity check failed',
);
this.wsCheckResult = false;
});
}
this.checkWsConnectivity()
.then(() => {
Logger.logAction(
this.logger,
Logger.LOG_MINOR,
'ConnectionManager WebSocket slow timer',
'ws connectivity check succeeded',
);
this.wsCheckResult = true;
})
.catch(() => {
Logger.logAction(
this.logger,
Logger.LOG_MAJOR,
'ConnectionManager WebSocket slow timer',
'ws connectivity check failed',
);
this.wsCheckResult = false;
});
if (this.realtime.http.checkConnectivity) {
Utils.whenPromiseSettles(this.realtime.http.checkConnectivity(), (err, connectivity) => {
if (err || !connectivity) {
Expand Down Expand Up @@ -1450,8 +1448,6 @@ class ConnectionManager extends EventEmitter {
if (transportPreference && transportPreference === this.baseTransport && this.webSocketTransportAvailable) {
this.checkWsConnectivity()
.then(() => {
this.wsCheckResult = true;
this.abandonedWebSocket = false;
this.unpersistTransportPreference();
if (this.state === this.states.connecting) {
Logger.logAction(
Expand Down Expand Up @@ -1493,6 +1489,8 @@ class ConnectionManager extends EventEmitter {
*/
connectWs(transportParams: TransportParams, connectCount: number) {
Logger.logAction(this.logger, Logger.LOG_MICRO, 'ConnectionManager.connectWs()');
this.wsCheckResult = null;
this.abandonedWebSocket = false;
this.startWebSocketSlowTimer();
this.startWebSocketGiveUpTimer(transportParams);

Expand Down

0 comments on commit d65b03d

Please sign in to comment.