summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal_binding/tcp_wrap.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal_binding/tcp_wrap.ts')
-rw-r--r--ext/node/polyfills/internal_binding/tcp_wrap.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/ext/node/polyfills/internal_binding/tcp_wrap.ts b/ext/node/polyfills/internal_binding/tcp_wrap.ts
index 9897bccd0..4b57a7e1e 100644
--- a/ext/node/polyfills/internal_binding/tcp_wrap.ts
+++ b/ext/node/polyfills/internal_binding/tcp_wrap.ts
@@ -45,6 +45,7 @@ import {
INITIAL_ACCEPT_BACKOFF_DELAY,
MAX_ACCEPT_BACKOFF_DELAY,
} from "ext:deno_node/internal_binding/_listen.ts";
+import { nextTick } from "ext:deno_node/_next_tick.ts";
/** The type of TCP socket. */
enum socketType {
@@ -228,7 +229,14 @@ export class TCP extends ConnectionWrap {
this.#port = address.port;
this.#listener = listener;
- this.#accept();
+
+ // TODO(kt3k): Delays the accept() call 2 ticks. Deno.Listener can't be closed
+ // synchronously when accept() is called. By delaying the accept() call,
+ // the user can close the server synchronously in the callback of listen().
+ // This workaround enables `npm:detect-port` to work correctly.
+ // Remove these nextTick calls when the below issue resolved:
+ // https://github.com/denoland/deno/issues/25480
+ nextTick(nextTick, () => this.#accept());
return 0;
}