fix: interrupted WebSocket connection not closed by LiveQuery server (#8012)

This commit is contained in:
Javad
2022-06-05 18:31:48 +04:30
committed by GitHub
parent 468e98785f
commit 2d5221e480
2 changed files with 32 additions and 1 deletions

View File

@@ -14,6 +14,10 @@ export class ParseWebSocketServer {
logger.info('Parse LiveQuery Server started running');
};
wss.onConnection = ws => {
ws.waitingForPong = false;
ws.on('pong', () => {
this.waitingForPong = false;
});
ws.on('error', error => {
logger.error(error.message);
logger.error(inspect(ws, false));
@@ -21,10 +25,12 @@ export class ParseWebSocketServer {
onConnect(new ParseWebSocket(ws));
// Send ping to client periodically
const pingIntervalId = setInterval(() => {
if (ws.readyState == ws.OPEN) {
if (!ws.waitingForPong) {
ws.ping();
ws.waitingForPong = true;
} else {
clearInterval(pingIntervalId);
ws.terminate();
}
}, config.websocketTimeout || 10 * 1000);
};