Compare commits

...

2 Commits

Author SHA1 Message Date
Damien Arrachequesne
4176a812ce fix tests 2025-12-23 16:40:44 +01:00
Damien Arrachequesne
2cd6d591dc fix(sio): do not throw when calling io.close() with an already stopped server 2025-12-23 15:47:33 +01:00
2 changed files with 24 additions and 4 deletions

View File

@@ -831,14 +831,13 @@ export class Server<
restoreAdapter();
if (this.httpServer) {
await new Promise<void>((resolve, reject) => {
return new Promise<void>((resolve) => {
this.httpServer.close((err) => {
fn && fn(err);
if (err) {
reject(err);
} else {
resolve();
debug("server was not running");
}
resolve();
});
});
} else {

View File

@@ -70,6 +70,27 @@ describe("close", () => {
});
});
it("should not throw when the underlying HTTP server is not running (callback)", (done) => {
const httpServer = createServer();
const io = new Server(httpServer);
io.close((err) => {
expect((err as Error & { code: string }).code).to.eql(
"ERR_SERVER_NOT_RUNNING",
);
done();
});
});
it("should not throw when the underlying HTTP server is not running (Promise)", (done) => {
const httpServer = createServer();
const io = new Server(httpServer);
io.close()
.then(() => done())
.catch((e) => done(e));
});
describe("graceful close", () => {
function fixture(filename) {
return (