Skip to content

Commit

Permalink
net: report uv_tcp_open() errors
Browse files Browse the repository at this point in the history
uv_tcp_open() can fail. Prior to this commit, any error was
being silently ignored. This commit raises the errors.
  • Loading branch information
cjihrig committed Jun 20, 2018
1 parent 0eb8a8c commit 6871816
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,14 @@ function Socket(options) {
this[async_id_symbol] = getNewAsyncId(this._handle);
} else if (options.fd !== undefined) {
const { fd } = options;
let err;

this._handle = createHandle(fd, false);
this._handle.open(fd);

err = this._handle.open(fd);
if (err)
throw errnoException(err, 'open');

this[async_id_symbol] = this._handle.getAsyncId();
// options.fd can be string (since it is user-defined),
// so changing this to === would be semver-major
Expand All @@ -270,7 +276,7 @@ function Socket(options) {
(this._handle instanceof Pipe) &&
process.platform === 'win32') {
// Make stdout and stderr blocking on Windows
var err = this._handle.setBlocking(true);
err = this._handle.setBlocking(true);
if (err)
throw errnoException(err, 'setBlocking');

Expand Down Expand Up @@ -1236,7 +1242,11 @@ function createServerHandle(address, port, addressType, fd) {
debug('listen invalid fd=%d:', fd, e.message);
return UV_EINVAL;
}
handle.open(fd);

err = handle.open(fd);
if (err)
return err;

handle.readable = true;
handle.writable = true;
assert(!address && !port);
Expand Down
3 changes: 2 additions & 1 deletion src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
args.Holder(),
args.GetReturnValue().Set(UV_EBADF));
int fd = static_cast<int>(args[0]->IntegerValue());
uv_tcp_open(&wrap->handle_, fd);
int err = uv_tcp_open(&wrap->handle_, fd);
wrap->set_fd(fd);
args.GetReturnValue().Set(err);
}


Expand Down

0 comments on commit 6871816

Please sign in to comment.