Merge pull request #3705 from mempool/mononaut/increase-websocket-timeout

Increase client websocket timeout
This commit is contained in:
softsimon 2023-05-04 01:35:16 +04:00 committed by GitHub
commit e807b3ca74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,8 +9,8 @@ import { take } from 'rxjs/operators';
import { TransferState, makeStateKey } from '@angular/platform-browser'; import { TransferState, makeStateKey } from '@angular/platform-browser';
import { BlockExtended } from '../interfaces/node-api.interface'; import { BlockExtended } from '../interfaces/node-api.interface';
const OFFLINE_RETRY_AFTER_MS = 1000; const OFFLINE_RETRY_AFTER_MS = 2000;
const OFFLINE_PING_CHECK_AFTER_MS = 10000; const OFFLINE_PING_CHECK_AFTER_MS = 30000;
const EXPECT_PING_RESPONSE_AFTER_MS = 5000; const EXPECT_PING_RESPONSE_AFTER_MS = 5000;
const initData = makeStateKey('/api/v1/init-data'); const initData = makeStateKey('/api/v1/init-data');
@ -119,7 +119,7 @@ export class WebsocketService {
}, },
(err: Error) => { (err: Error) => {
console.log(err); console.log(err);
console.log(`WebSocket error, trying to reconnect in ${OFFLINE_RETRY_AFTER_MS} seconds`); console.log(`WebSocket error`);
this.goOffline(); this.goOffline();
}); });
} }
@ -208,11 +208,13 @@ export class WebsocketService {
} }
goOffline() { goOffline() {
const retryDelay = OFFLINE_RETRY_AFTER_MS + (Math.random() * OFFLINE_RETRY_AFTER_MS);
console.log(`trying to reconnect websocket in ${retryDelay} seconds`);
this.goneOffline = true; this.goneOffline = true;
this.stateService.connectionState$.next(0); this.stateService.connectionState$.next(0);
window.setTimeout(() => { window.setTimeout(() => {
this.startSubscription(true); this.startSubscription(true);
}, OFFLINE_RETRY_AFTER_MS); }, retryDelay);
} }
startOnlineCheck() { startOnlineCheck() {
@ -223,7 +225,7 @@ export class WebsocketService {
this.websocketSubject.next({action: 'ping'}); this.websocketSubject.next({action: 'ping'});
this.onlineCheckTimeoutTwo = window.setTimeout(() => { this.onlineCheckTimeoutTwo = window.setTimeout(() => {
if (!this.goneOffline) { if (!this.goneOffline) {
console.log('WebSocket response timeout, force closing, trying to reconnect in 10 seconds'); console.log('WebSocket response timeout, force closing');
this.websocketSubject.complete(); this.websocketSubject.complete();
this.subscription.unsubscribe(); this.subscription.unsubscribe();
this.goOffline(); this.goOffline();