Skip to content

Commit 8646b06

Browse files
vramanadanielleadams
authored andcommitted
dgram: fix unhandled exception aborting a closed udp socket
Fixes: #46750 PR-URL: #46770 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 63a62ed commit 8646b06

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/dgram.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function Socket(type, listener) {
139139
const { signal } = options;
140140
validateAbortSignal(signal, 'options.signal');
141141
const onAborted = () => {
142-
this.close();
142+
if (this[kStateSymbol].handle) this.close();
143143
};
144144
if (signal.aborted) {
145145
onAborted();
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
require('../common');
3+
const dgram = require('dgram');
4+
5+
const controller = new AbortController();
6+
const socket = dgram.createSocket({ type: 'udp4', signal: controller.signal });
7+
8+
socket.close();
9+
10+
controller.abort();

0 commit comments

Comments
 (0)