Merge branch 'main' into fix/module-format
This commit is contained in:
commit
b2b1920c8b
2 changed files with 39 additions and 0 deletions
28
src/integration-tests/process-cleanup.test.ts
Normal file
28
src/integration-tests/process-cleanup.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { Server } from "../server/index.js";
|
||||
import { StdioServerTransport } from "../server/stdio.js";
|
||||
|
||||
describe("Process cleanup", () => {
|
||||
jest.setTimeout(5000); // 5 second timeout
|
||||
|
||||
it("should exit cleanly after closing transport", async () => {
|
||||
const server = new Server(
|
||||
{
|
||||
name: "test-server",
|
||||
version: "1.0.0",
|
||||
},
|
||||
{
|
||||
capabilities: {},
|
||||
}
|
||||
);
|
||||
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
|
||||
// Close the transport
|
||||
await transport.close();
|
||||
|
||||
// If we reach here without hanging, the test passes
|
||||
// The test runner will fail if the process hangs
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -62,8 +62,19 @@ export class StdioServerTransport implements Transport {
|
|||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
// Remove our event listeners first
|
||||
this._stdin.off("data", this._ondata);
|
||||
this._stdin.off("error", this._onerror);
|
||||
|
||||
// Check if we were the only data listener
|
||||
const remainingDataListeners = this._stdin.listenerCount('data');
|
||||
if (remainingDataListeners === 0) {
|
||||
// Only pause stdin if we were the only listener
|
||||
// This prevents interfering with other parts of the application that might be using stdin
|
||||
this._stdin.pause();
|
||||
}
|
||||
|
||||
// Clear the buffer and notify closure
|
||||
this._readBuffer.clear();
|
||||
this.onclose?.();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue