mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-21 19:38:29 +00:00
fix: send ping every 60 seconds, to keep the connection alive
This commit is contained in:
parent
c488d08483
commit
ebf9a0b05e
@ -127,8 +127,20 @@ async function createTransport(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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.
|
||||||
|
logger.error("Failed to send keep-alive ping, cleaning up interval." + e);
|
||||||
|
clearInterval(keepAlive);
|
||||||
|
}
|
||||||
|
}, 60000); // Send ping every 60 seconds
|
||||||
|
|
||||||
// Setup cleanup on close
|
// Setup cleanup on close
|
||||||
transport.onclose = async () => {
|
transport.onclose = async () => {
|
||||||
|
clearInterval(keepAlive);
|
||||||
await MCPSessionManager.deleteSession(sessionId);
|
await MCPSessionManager.deleteSession(sessionId);
|
||||||
await TransportManager.cleanupSession(sessionId);
|
await TransportManager.cleanupSession(sessionId);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user