From d961de0d3226469bcebc7d8fc3f84b9b4586c60f Mon Sep 17 00:00:00 2001 From: Steven Gabarro Date: Wed, 7 Nov 2018 05:54:13 -0500 Subject: [PATCH 1/4] net: remove unreachable error When creating a socket, if the file descriptor is not a valid PIPE or TCP type, createHandle throws an ERR_INVALID_FD_TYPE. This means that `this._handle.open` is guaranteed to succeed and will never return an error. --- lib/net.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/net.js b/lib/net.js index 05fc4fa9598b04..1f3598ffa90932 100644 --- a/lib/net.js +++ b/lib/net.js @@ -266,9 +266,7 @@ function Socket(options) { this._handle = createHandle(fd, false); - err = this._handle.open(fd); - if (err) - throw errnoException(err, 'open'); + this._handle.open(fd); this[async_id_symbol] = this._handle.getAsyncId(); // options.fd can be string (since it is user-defined), From 4899951ff0c7458a11adc7230be110edf2fb0c58 Mon Sep 17 00:00:00 2001 From: bewchy Date: Tue, 13 Nov 2018 12:12:29 -0500 Subject: [PATCH 2/4] net: add comments on unreachable error check --- lib/net.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 1f3598ffa90932..88848130c1157a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -264,9 +264,17 @@ function Socket(options) { const { fd } = options; let err; + // createHandle will throw ERR_INVALID_FD_TYPE if `fd` is not + // a valid `PIPE` or `TCP` descriptor this._handle = createHandle(fd, false); - this._handle.open(fd); + err = this._handle.open(fd); + + // While difficult to fabricate, in some architectures, `open` may return an error + // code for valid file descriptors which cannot be openned + // This is difficult to test as most un-openable fds will throw on `createHandle` + if (err) + throw errnoException(err, 'open'); this[async_id_symbol] = this._handle.getAsyncId(); // options.fd can be string (since it is user-defined), From f7565e649d55f30226816fc6df911b5bbb644dce Mon Sep 17 00:00:00 2001 From: bewchy Date: Tue, 13 Nov 2018 12:50:33 -0500 Subject: [PATCH 3/4] net: add comments explaining error check This new commit re-formats the comments for linting checks --- lib/net.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/net.js b/lib/net.js index 88848130c1157a..3026669e029f33 100644 --- a/lib/net.js +++ b/lib/net.js @@ -270,9 +270,10 @@ function Socket(options) { err = this._handle.open(fd); - // While difficult to fabricate, in some architectures, `open` may return an error - // code for valid file descriptors which cannot be openned - // This is difficult to test as most un-openable fds will throw on `createHandle` + // While difficult to fabricate, in some architectures + // `open` may return an error code for valid file descriptors + // which cannot be openned. This is difficult to test as most + // un-openable fds will throw on `createHandle` if (err) throw errnoException(err, 'open'); From e0eb104c3a24a85e4c3569397f396b3337488a34 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Tue, 13 Nov 2018 16:32:45 -0500 Subject: [PATCH 4/4] net: add comments to Socket constructor Co-Authored-By: bewchy --- lib/net.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net.js b/lib/net.js index 3026669e029f33..089c69beb769cd 100644 --- a/lib/net.js +++ b/lib/net.js @@ -272,7 +272,7 @@ function Socket(options) { // While difficult to fabricate, in some architectures // `open` may return an error code for valid file descriptors - // which cannot be openned. This is difficult to test as most + // which cannot be opened. This is difficult to test as most // un-openable fds will throw on `createHandle` if (err) throw errnoException(err, 'open');