[ide-mode] Send ping every 30 seconds to prevent client from closing connection (#4329)

This commit is contained in:
christine betts 2025-07-18 19:33:04 +00:00 committed by GitHub
parent 18c3bf3a42
commit d7041a6595
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -75,7 +75,22 @@ export class IDEServer {
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 = () => {
clearInterval(keepAlive);
if (transport.sessionId) {
this.logger.appendLine(`Session closed: ${transport.sessionId}`);
sessionsWithInitialNotification.delete(transport.sessionId);