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.

PR-URL: #21428
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Jun 24, 2018
1 parent 881d99b commit 50f833d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,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 @@ -271,7 +277,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 @@ -1237,7 +1243,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
8 changes: 6 additions & 2 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ 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);
wrap->set_fd(fd);
int err = uv_tcp_open(&wrap->handle_, fd);

if (err == 0)
wrap->set_fd(fd);

args.GetReturnValue().Set(err);
}


Expand Down

0 comments on commit 50f833d

Please sign in to comment.