Browse Source

fix(BridgeChannel): prevent multiple websockets on retries (#2179)

* fix(BridgeChannel): prevent multiple websockets on retries

* fix(BridgeChannel): ignore different websocket close event

* fix(BridgeChannel): Keep onclose log

* ref: Add comment for retry timeout on connecting ws

* ref: Use logger debug instead info
tags/v0.0.2
Ilya Sunduev 3 years ago
parent
commit
a373005103
No account linked to committer's email address
1 changed files with 19 additions and 1 deletions
  1. 19
    1
      modules/RTC/BridgeChannel.js

+ 19
- 1
modules/RTC/BridgeChannel.js View File

@@ -100,6 +100,18 @@ export default class BridgeChannel {
100 100
         let timeoutS = 1;
101 101
 
102 102
         const reload = () => {
103
+            const isConnecting = this._channel && (this._channel.readyState === 'connecting'
104
+                    || this._channel.readyState === WebSocket.CONNECTING);
105
+
106
+            // Should not spawn new websockets while one is already trying to connect.
107
+            if (isConnecting) {
108
+                // Timeout is still required as there is flag `_areRetriesEnabled` that
109
+                // blocks new retrying cycles until any channel opens in current cycle.
110
+                this._retryTimeout = setTimeout(reload, timeoutS * 1000);
111
+
112
+                return;
113
+            }
114
+
103 115
             if (this.isOpen()) {
104 116
                 return;
105 117
             }
@@ -410,7 +422,13 @@ export default class BridgeChannel {
410 422
         };
411 423
 
412 424
         channel.onclose = event => {
413
-            logger.info(`Channel closed by ${this._closedFromClient ? 'client' : 'server'}`);
425
+            logger.debug(`Channel closed by ${this._closedFromClient ? 'client' : 'server'}`);
426
+
427
+            if (channel !== this._channel) {
428
+                logger.debug('Skip close handler, channel instance is not equal to stored one');
429
+
430
+                return;
431
+            }
414 432
 
415 433
             if (this._mode === 'websocket') {
416 434
                 if (!this._closedFromClient) {

Loading…
Cancel
Save