-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
src: ensure that fd 0-2 are valid on windows #11863
Conversation
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: nodejs#875 Fixes: nodejs#11656
cc @nodejs/platform-windows |
CI failed on win2008 and 2012, I'll investigate. |
ping @bnoordhuis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from a distance ;) It’s been too long since I worked with Windows APIs to give this a proper LGTM, even if it’s only a few lines of code.
test/fixtures/spawn_closed_stdio.py
Outdated
os.close(0) | ||
os.close(1) | ||
os.close(2) | ||
cmd = sys.argv[1] + ' -e "process.stdin; process.stdout; process.stderr;"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer it if the arguments came from the test file, i.e. you just spawn sys.argv[1]
here and move the -e …
bits to test-stdio-closed.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do use -e, write this as cmd = sys.argv[1:2] + ['-e', 'process.stdin; ...']
so it gets escaped properly.
src/node.cc
Outdated
@@ -4213,6 +4213,16 @@ inline void PlatformInit() { | |||
} while (min + 1 < max); | |||
} | |||
#endif // __POSIX__ | |||
#ifdef _WIN32 | |||
for (int fd = 0; fd <= 2; ++fd) { | |||
auto handle = (HANDLE) _get_osfhandle(fd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the appropriate C++-style cast here, whichever one that is?
test/fixtures/spawn_closed_stdio.py
Outdated
os.close(0) | ||
os.close(1) | ||
os.close(2) | ||
cmd = sys.argv[1] + ' -e "process.stdin; process.stdout; process.stderr;"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do use -e, write this as cmd = sys.argv[1:2] + ['-e', 'process.stdin; ...']
so it gets escaped properly.
test/parallel/test-stdio-closed.js
Outdated
|
||
if (common.isWindows) { | ||
common.skip('platform not supported.'); | ||
const python = process.env.PYTHON || 'python'; | ||
const script = path.join(__dirname, '..', 'fixtures', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.join(common.fixturesDir, 'spawn_closed_stdio.py')
?
Updated, CI is green, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a question.
src/node.cc
Outdated
auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd)); | ||
if (handle == INVALID_HANDLE_VALUE || | ||
GetFileType(handle) == FILE_TYPE_UNKNOWN) { | ||
_close(fd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_close()
can't fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails on Windows 2008 and 2012 but succeeds on Windows 10. IMHO the cleanest way is to just assert that _open
returned proper fd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it known why it can fail on 2008/2012 and can that be worked around at all? I'm good with this as is but I'm curious :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win2008 and 2012 fail with errno EBADF
. Win 10 happily closes the handle. But regardless of that, _open
works as expected on all Win versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bzoz actually, having this explanation as a comment in the source seems like a good idea to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh not really sure about my review on this, CI passes and stuff I guess? ¯\_(ツ)_/¯
@addaleax I've added a comment about |
Landed in bd496e0 |
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: #875 Fixes: #11656 PR-URL: #11863 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: #875 Fixes: #11656 PR-URL: #11863 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
landed in v4.x and v6x staging |
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: #875 Fixes: #11656 PR-URL: #11863 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: #875 Fixes: #11656 PR-URL: #11863 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
nodejs#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc.
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: #12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: nodejs/node#875 Fixes: nodejs/node#11656 PR-URL: nodejs/node#11863 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
nodejs/node#11863 adds _O_RDWR to node.cc which is defined in fcntl.h. This adds this include directly to node.cc. PR-URL: nodejs/node#12540 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Check that
stdin
,stdout
andstderr
are valid file descriptors on Windows. If not, reopen them withnul
file.This is a port of #875 for Windows.
Fixes: #11656
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
src