diff --git a/lib/dgram.js b/lib/dgram.js index 6af6460f4eb78d..9c2837eb51fba5 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -30,6 +30,7 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, ReflectApply, + SymbolDispose, } = primordials; const errors = require('internal/errors'); @@ -144,8 +145,8 @@ function Socket(type, listener) { if (signal.aborted) { onAborted(); } else { - signal.addEventListener('abort', onAborted); - this.once('close', () => signal.removeEventListener('abort', onAborted)); + const disposable = EventEmitter.addAbortListener(signal, onAborted); + this.once('close', disposable[SymbolDispose]); } } if (udpSocketChannel.hasSubscribers) {