Skip to content

Commit

Permalink
dgram: reset bind state before emitting error
Browse files Browse the repository at this point in the history
This was previously done inconsistently, sometimes before, sometimes
after emitting the event.

PR-URL: #30210
Fixes: #30209
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed Dec 17, 2019
1 parent e1a1244 commit fd5fed1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
}, (err) => {
// Callback to handle error.
const ex = errnoException(err, 'open');
this.emit('error', ex);
state.bindState = BIND_STATE_UNBOUND;
this.emit('error', ex);
});
return this;
}
Expand Down Expand Up @@ -309,8 +309,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
}, (err) => {
// Callback to handle error.
const ex = exceptionWithHostPort(err, 'bind', ip, port);
this.emit('error', ex);
state.bindState = BIND_STATE_UNBOUND;
this.emit('error', ex);
});
} else {
if (!state.handle)
Expand All @@ -319,8 +319,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
const err = state.handle.bind(ip, port || 0, flags);
if (err) {
const ex = exceptionWithHostPort(err, 'bind', ip, port);
this.emit('error', ex);
state.bindState = BIND_STATE_UNBOUND;
this.emit('error', ex);
// Todo: close?
return;
}
Expand Down

0 comments on commit fd5fed1

Please sign in to comment.