Fix a lifecycle bug with server everything in stdio mode (#2848)
This commit is contained in:
parent
8e0c890337
commit
76dcff0617
1 changed files with 7 additions and 3 deletions
|
|
@ -9,14 +9,18 @@ async function main() {
|
||||||
const transport = new StdioServerTransport();
|
const transport = new StdioServerTransport();
|
||||||
const {server, cleanup, startNotificationIntervals} = createServer();
|
const {server, cleanup, startNotificationIntervals} = createServer();
|
||||||
|
|
||||||
|
// Cleanup when client disconnects
|
||||||
|
server.onclose = async () => {
|
||||||
|
await cleanup();
|
||||||
|
process.exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
startNotificationIntervals();
|
startNotificationIntervals();
|
||||||
|
|
||||||
// Cleanup on exit
|
// Cleanup on exit
|
||||||
process.on("SIGINT", async () => {
|
process.on("SIGINT", async () => {
|
||||||
await cleanup();
|
await server.close();
|
||||||
await server.close();
|
|
||||||
process.exit(0);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue