diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-09-08 12:22:18 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-08 12:22:18 +0900 |
commit | ce1d668929a91da2dc204f6bcc53afd5173c0a33 (patch) | |
tree | 2f240019e47fe3166e5f369c5aa36f1023313158 /tests/unit_node | |
parent | 30687c786c37090ac0e4e2c3824b1b5cf313599f (diff) |
fix(ext/node): delay accept() call 2 ticks in net.Server#listen (#25481)
A workaround for the issue #25480
`Deno.Listener` can't be closed synchronously after `accept()` is
called. This PR delays the `accept` call 2 ticks (The listener callback
is called 1 tick later. So the 1 tick delay is not enough), and makes
`net.Server` capable of being closed synchronously.
This unblocks `npm:detect-port` and `npm:portfinder`
closes #18301
closes #25175
Diffstat (limited to 'tests/unit_node')
-rw-r--r-- | tests/unit_node/net_test.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unit_node/net_test.ts b/tests/unit_node/net_test.ts index 708d06386..8196874f3 100644 --- a/tests/unit_node/net_test.ts +++ b/tests/unit_node/net_test.ts @@ -228,3 +228,22 @@ Deno.test("[node/net] BlockList doesn't leak resources", () => { blockList.addAddress("1.1.1.1"); assert(blockList.check("1.1.1.1")); }); + +Deno.test("[node/net] net.Server can listen on the same port immediately after it's closed", async () => { + const serverClosed = Promise.withResolvers<void>(); + const server = net.createServer(); + server.on("error", (e) => { + console.error(e); + }); + server.listen(0, () => { + // deno-lint-ignore no-explicit-any + const { port } = server.address() as any; + server.close(); + server.listen(port, () => { + server.close(() => { + serverClosed.resolve(); + }); + }); + }); + await serverClosed.promise; +}); |