mirror of
https://github.com/mempool/mempool.git
synced 2025-02-24 06:47:52 +01:00
Merge pull request #3705 from mempool/mononaut/increase-websocket-timeout
Increase client websocket timeout
This commit is contained in:
commit
e807b3ca74
1 changed files with 7 additions and 5 deletions
|
@ -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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue