Skip to content

Commit d37e287

Browse files
committed
fix(server): clean sigint handler on shutdown
1 parent 28af53c commit d37e287

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/server.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const runServer = async (options: ServerOptions = getOptions(), {
129129
let transport: StdioServerTransport | null = null;
130130
let httpHandle: HttpServerHandle | null = null;
131131
let unsubscribeServerLogger: (() => void) | null = null;
132+
let sigintHandler: (() => void) | null = null;
132133
let running = false;
133134
let onLogSetup: ServerOnLog = () => () => {};
134135

@@ -144,6 +145,11 @@ const runServer = async (options: ServerOptions = getOptions(), {
144145
httpHandle = null;
145146
}
146147

148+
if (sigintHandler) {
149+
process.off('SIGINT', sigintHandler);
150+
sigintHandler = null;
151+
}
152+
147153
log.debug('...closing Server');
148154
await server?.close();
149155
running = false;
@@ -246,10 +252,11 @@ const runServer = async (options: ServerOptions = getOptions(), {
246252
})));
247253
});
248254

249-
if (enableSigint) {
250-
process.on('SIGINT', () => {
255+
if (enableSigint && !sigintHandler) {
256+
sigintHandler = () => {
251257
void stopServer();
252-
});
258+
};
259+
process.on('SIGINT', sigintHandler);
253260
}
254261

255262
if (options.isHttp) {

0 commit comments

Comments
 (0)