Skip to content

Commit e8206ae

Browse files
committed
fixup! net: server add asyncDispose
1 parent 04ec986 commit e8206ae

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/net.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,9 @@ Server.prototype.close = function(cb) {
22442244
};
22452245

22462246
Server.prototype[SymbolAsyncDispose] = async function() {
2247+
if (!this._handle) {
2248+
return;
2249+
}
22472250
return FunctionPrototypeCall(promisify(this.close), this);
22482251
};
22492252

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import * as common from '../common/index.mjs';
22
import assert from 'node:assert';
33
import net from 'node:net';
4-
import { test } from 'node:test';
4+
import { describe, it } from 'node:test';
55

6-
test('net.Server[Symbol.asyncDispose]()', () => {
7-
const server = net.createServer();
6+
describe('net.Server[Symbol.asyncDispose]()', () => {
7+
it('should close the server', async () => {
8+
const server = net.createServer();
9+
const timeoutRef = setTimeout(common.mustNotCall(), 2 ** 31 - 1);
810

9-
server.listen(0, common.mustCall(async () => {
10-
await server[Symbol.asyncDispose]().then(common.mustCall());
11-
assert.strictEqual(server.address(), null);
12-
}));
11+
server.listen(0, common.mustCall(async () => {
12+
await server[Symbol.asyncDispose]().then(common.mustCall());
13+
assert.strictEqual(server.address(), null);
14+
clearTimeout(timeoutRef);
15+
}));
1316

14-
server.on('close', common.mustCall());
17+
server.on('close', common.mustCall());
18+
});
19+
20+
it('should resolve even if the server is already closed', async () => {
21+
const server = net.createServer();
22+
const timeoutRef = setTimeout(common.mustNotCall(), 2 ** 31 - 1);
23+
24+
server.listen(0, common.mustCall(async () => {
25+
await server[Symbol.asyncDispose]().then(common.mustCall());
26+
await server[Symbol.asyncDispose]().then(common.mustCall(), common.mustNotCall());
27+
clearTimeout(timeoutRef);
28+
}));
29+
});
1530
});

0 commit comments

Comments
 (0)