-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
uv_close: Assertion `0' failed on child_process.execSync w/ Infinite maxBuffer #8096
Comments
I can reproduce. This happens when invalid values are detected in ParseOptions. |
backtrace:
|
I'm testing a fix |
diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc
index 79f10a0..8cded31 100644
--- a/src/spawn_sync.cc
+++ b/src/spawn_sync.cc
@@ -501,7 +501,7 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
// Close the process handle when ExitCallback was not called.
uv_handle_t* uv_process_handle =
reinterpret_cast<uv_handle_t*>(&uv_process_);
- if (!uv_is_closing(uv_process_handle))
+ if (!uv_is_closing(uv_process_handle) && uv_process_handle->type != 0)
uv_close(uv_process_handle, nullptr);
// Give closing watchers a chance to finish closing and get their close This prevents the problem but it is probably not the correct fix. |
BTW without the abort, the thrown exception is not very informative:
Is there any reason we don't have a preliminary check of the options in JS ? |
The issue is that CloseHandlesAndDeleteLoop() tries to close handles that TryInitializeAndRunLoop() doesn't initialize when ParseOptions() fails. Untested, but a quick fix would look like this: diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc
index 79f10a0..9a9ec4a 100644
--- a/src/spawn_sync.cc
+++ b/src/spawn_sync.cc
@@ -422,8 +422,13 @@ Local<Object> SyncProcessRunner::Run(Local<Value> options) {
CHECK_EQ(lifecycle_, kUninitialized);
- TryInitializeAndRunLoop(options);
- CloseHandlesAndDeleteLoop();
+ int r = ParseOptions(options);
+ if (r < 0) {
+ SetError(r);
+ } else {
+ TryInitializeAndRunLoop(options);
+ CloseHandlesAndDeleteLoop();
+ }
Local<Object> result = BuildResultObject();
@@ -444,10 +449,6 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
return SetError(UV_ENOMEM);
CHECK_EQ(uv_loop_init(uv_loop_), 0);
- r = ParseOptions(options);
- if (r < 0)
- return SetError(r);
-
if (timeout_ > 0) {
r = uv_timer_init(uv_loop_, &uv_timer_);
if (r < 0) That produces an unhelpful EINVAL error though, and it doesn't address the wider issue that SyncProcessRunner is sloppy with its bookkeeping. TryInitializeAndRunLoop() can still fail for other reasons. |
@bnoordhuis It's more complex. AddStdioPipe (used in ParseOptions) needs |
This commit verifies that the child process handle is of the correct type before trying to close it in CloseHandlesAndDeleteLoop(). This catches the case where input validation failed, and the child process was never actually spawned. Fixes: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit applies stricter input validation in normalizeSpawnArguments(), which is run by all of the child_process methods. Additional checks are added for spawnSync() specific inputs. Fixes: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit removes C++ checks from spawn() and spawnSync() that are duplicates of the JavaScript type checking. Fixes: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit verifies that the child process handle is of the correct type before trying to close it in CloseHandlesAndDeleteLoop(). This catches the case where input validation failed, and the child process was never actually spawned. Fixes: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit applies stricter input validation in normalizeSpawnArguments(), which is run by all of the child_process methods. Additional checks are added for spawnSync() specific inputs. Fixes: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit removes C++ checks from spawn() and spawnSync() that are duplicates of the JavaScript type checking. Fixes: nodejs#8096 Fixes: nodejs#8539 Refs: nodejs#9722 PR-URL: nodejs#8312 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux
Reproduce:
Not that the async
exec
does not exert the same behaviourThe text was updated successfully, but these errors were encountered: