mirror of
https://github.com/morluto/rea.git
synced 2026-11-03 05:16:16 +00:00
fix(mcp): close the listener before dropping open connections
closeAllConnections() ran before close(), so a connection accepted in between missed the forced-close pass and close() could wait for its request timeout. close() now starts first and closeAllConnections() follows immediately, as Node documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
964109a9b2
commit
b6bb74ed9f
1 file changed
+5
-3
@@ -385,16 +385,18 @@ export const serveStreamableHttp = async (
|
||||
return { url, close };
|
||||
};
|
||||
|
||||
/** Drop open connections and release the port. */
|
||||
/** Stop accepting, drop open connections and release the port. */
|
||||
const closeHttpServer = (
|
||||
httpServer: ReturnType<typeof createHttpServer>,
|
||||
): Promise<void> => {
|
||||
httpServer.closeAllConnections();
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
// close() first, as Node documents: a connection accepted before it would otherwise miss the forced-close pass.
|
||||
const closed = new Promise<void>((resolve, reject) => {
|
||||
httpServer.close((error) =>
|
||||
error === undefined ? resolve() : reject(error),
|
||||
);
|
||||
});
|
||||
httpServer.closeAllConnections();
|
||||
return closed;
|
||||
};
|
||||
|
||||
/** Translate one node:http exchange through `route`, logging a failure and answering it when headers are still open. */
|
||||
|
||||
Reference in new issue
Block a user