Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: report uv_tcp_open() errors #21428

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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