diff --git a/lib/net.js b/lib/net.js index 5f20f08c486d22..337402fc8d334a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -264,9 +264,16 @@ 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); 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 opened. This is difficult to test as most + // un-openable fds will throw on `createHandle` if (err) throw errnoException(err, 'open');