[ide-mode] Send ping every 30 seconds to prevent client from closing connection (#4329)
This commit is contained in:
parent
18c3bf3a42
commit
d7041a6595
|
@ -75,7 +75,22 @@ export class IDEServer {
|
||||||
transports[newSessionId] = transport;
|
transports[newSessionId] = transport;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const keepAlive = setInterval(() => {
|
||||||
|
try {
|
||||||
|
transport.send({ jsonrpc: '2.0', method: 'ping' });
|
||||||
|
} catch (e) {
|
||||||
|
// If sending a ping fails, the connection is likely broken.
|
||||||
|
// Log the error and clear the interval to prevent further attempts.
|
||||||
|
this.logger.append(
|
||||||
|
'Failed to send keep-alive ping, cleaning up interval.' + e,
|
||||||
|
);
|
||||||
|
clearInterval(keepAlive);
|
||||||
|
}
|
||||||
|
}, 60000); // Send ping every 60 seconds
|
||||||
|
|
||||||
transport.onclose = () => {
|
transport.onclose = () => {
|
||||||
|
clearInterval(keepAlive);
|
||||||
if (transport.sessionId) {
|
if (transport.sessionId) {
|
||||||
this.logger.appendLine(`Session closed: ${transport.sessionId}`);
|
this.logger.appendLine(`Session closed: ${transport.sessionId}`);
|
||||||
sessionsWithInitialNotification.delete(transport.sessionId);
|
sessionsWithInitialNotification.delete(transport.sessionId);
|
||||||
|
|
Loading…
Reference in New Issue