diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-07-24 20:33:45 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-24 20:33:45 +0900 |
commit | 199a8ca4c5a8c5b2a060ef6a8912766a6a98d0b7 (patch) | |
tree | f285ddbf9fa59687d5d0bc3610152af41f887a30 /ext | |
parent | 29934d558c188fdc3406706da19921ca5a389383 (diff) |
fix(ext/node/net): emit `error` before `close` when connection is refused (#24656)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/node/polyfills/dgram.ts | 17 | ||||
-rw-r--r-- | ext/node/polyfills/internal_binding/handle_wrap.ts | 7 |
2 files changed, 13 insertions, 11 deletions
diff --git a/ext/node/polyfills/dgram.ts b/ext/node/polyfills/dgram.ts index 17ec4f2c3..99f4940ec 100644 --- a/ext/node/polyfills/dgram.ts +++ b/ext/node/polyfills/dgram.ts @@ -531,16 +531,17 @@ export class Socket extends EventEmitter { healthCheck(this); stopReceiving(this); - state.handle!.close(); + state.handle!.close(() => { + // Deviates from the Node implementation to avoid leaking the timer ops at 'close' event + defaultTriggerAsyncIdScope( + this[asyncIdSymbol], + nextTick, + socketCloseNT, + this, + ); + }); state.handle = null; - defaultTriggerAsyncIdScope( - this[asyncIdSymbol], - nextTick, - socketCloseNT, - this, - ); - return this; } diff --git a/ext/node/polyfills/internal_binding/handle_wrap.ts b/ext/node/polyfills/internal_binding/handle_wrap.ts index fd17a1edb..ef8457338 100644 --- a/ext/node/polyfills/internal_binding/handle_wrap.ts +++ b/ext/node/polyfills/internal_binding/handle_wrap.ts @@ -25,13 +25,12 @@ // - https://github.com/nodejs/node/blob/master/src/handle_wrap.h // TODO(petamoriken): enable prefer-primordials for node polyfills -// deno-lint-ignore-file prefer-primordials - import { unreachable } from "ext:deno_node/_util/asserts.ts"; import { AsyncWrap, providerType, } from "ext:deno_node/internal_binding/async_wrap.ts"; +import { nextTick } from "ext:deno_node/_process/process.ts"; export class HandleWrap extends AsyncWrap { constructor(provider: providerType) { @@ -40,7 +39,9 @@ export class HandleWrap extends AsyncWrap { close(cb: () => void = () => {}) { this._onClose(); - queueMicrotask(cb); + // We need to delay 'cb' at least 2 ticks to avoid "close" event happenning before "error" event in net.Socket + // See https://github.com/denoland/deno/pull/24656 for more information + nextTick(nextTick, cb); } ref() { |