Skip to content

Commit

Permalink
dgram: fix unhandled exception aborting a closed udp socket
Browse files Browse the repository at this point in the history
  • Loading branch information
vramana committed Feb 22, 2023
1 parent fda0de4 commit ba3fa6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Socket(type, listener) {
const { signal } = options;
validateAbortSignal(signal, 'options.signal');
const onAborted = () => {
this.close();
if (this[kStateSymbol].handle) this.close();
};
if (signal.aborted) {
onAborted();
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-dgram-abort-closed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const dgram = require('dgram');

const controller = new AbortController();
const socket = dgram.createSocket({ type: 'udp4', signal: controller.signal });

socket.close();

controller.abort();

0 comments on commit ba3fa6c

Please sign in to comment.