Recreate graphql ws client only as last resort
Try to force a reconnection by terminating the client first.
This commit is contained in:
@@ -324,16 +324,28 @@ export class GraphQLClient extends BaseClient<
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let triedForcedReconnection = false;
|
||||||
let lastHeartbeat: number = Date.now();
|
let lastHeartbeat: number = Date.now();
|
||||||
this.wsClient.on('pong', () => {
|
this.wsClient.on('message', () => {
|
||||||
lastHeartbeat = Date.now();
|
lastHeartbeat = Date.now();
|
||||||
|
triedForcedReconnection = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkHeartbeatInterval = heartbeatInterval + d(30).seconds.inWholeMilliseconds;
|
const checkHeartbeatInterval = heartbeatInterval + d(30).seconds.inWholeMilliseconds;
|
||||||
clearInterval(this.wsClientAliveCheckInterval);
|
clearInterval(this.wsClientAliveCheckInterval);
|
||||||
this.wsClientAliveCheckInterval = setInterval(() => {
|
this.wsClientAliveCheckInterval = setInterval(() => {
|
||||||
const isHeartbeatMissing = Date.now() - lastHeartbeat > checkHeartbeatInterval * 1.1;
|
const isHeartbeatMissing = Date.now() - lastHeartbeat > checkHeartbeatInterval * 1.1;
|
||||||
if (isHeartbeatMissing) {
|
if (!isHeartbeatMissing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!triedForcedReconnection) {
|
||||||
|
triedForcedReconnection = true;
|
||||||
|
this.wsClient.terminate();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.wsClient.dispose();
|
this.wsClient.dispose();
|
||||||
this.wsClient.terminate();
|
this.wsClient.terminate();
|
||||||
|
|
||||||
@@ -341,7 +353,6 @@ export class GraphQLClient extends BaseClient<
|
|||||||
this.client.setLink(this.createLink());
|
this.client.setLink(this.createLink());
|
||||||
|
|
||||||
this.activeConnectionSubscriptions.forEach((callback) => callback());
|
this.activeConnectionSubscriptions.forEach((callback) => callback());
|
||||||
}
|
|
||||||
}, checkHeartbeatInterval);
|
}, checkHeartbeatInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user