Fix for the websocket DOS bug.

This commit is contained in:
softsimon 2020-03-13 18:00:34 +07:00
parent 0bf337b7a6
commit e351bcea73
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -20,7 +20,6 @@ export class WebsocketService {
private latestGitCommit = ''; private latestGitCommit = '';
private onlineCheckTimeout: number; private onlineCheckTimeout: number;
private onlineCheckTimeoutTwo: number; private onlineCheckTimeoutTwo: number;
private connectionCheckTimeout: number;
private subscription: Subscription; private subscription: Subscription;
constructor( constructor(
@ -30,16 +29,7 @@ export class WebsocketService {
} }
startSubscription(retrying = false) { startSubscription(retrying = false) {
this.connectionCheckTimeout = window.setTimeout(() => {
console.log('WebSocket failed to connect, force closing, trying to reconnect');
this.websocketSubject.complete();
this.subscription.unsubscribe();
this.goOffline(true);
}, 10000);
if (retrying) { if (retrying) {
if (this.stateService.connectionState$.value === 2) {
return;
}
this.stateService.connectionState$.next(1); this.stateService.connectionState$.next(1);
} }
this.websocketSubject.next({'action': 'init'}); this.websocketSubject.next({'action': 'init'});
@ -128,7 +118,6 @@ export class WebsocketService {
this.stateService.connectionState$.next(2); this.stateService.connectionState$.next(2);
} }
clearTimeout(this.connectionCheckTimeout);
this.startOnlineCheck(); this.startOnlineCheck();
}, },
(err: Error) => { (err: Error) => {
@ -157,12 +146,12 @@ export class WebsocketService {
this.lastWant = data; this.lastWant = data;
} }
goOffline(instant = false) { goOffline() {
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);
}, instant ? 10 : 10000); }, 10000);
} }
startOnlineCheck() { startOnlineCheck() {