diff options
Diffstat (limited to 'ext/node')
-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() { |