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

child_process: empty options.env results in ENOMEM error #29008

Closed
ilikesleeping opened this issue Aug 6, 2019 · 4 comments · Fixed by #29070
Closed

child_process: empty options.env results in ENOMEM error #29008

ilikesleeping opened this issue Aug 6, 2019 · 4 comments · Fixed by #29070
Labels
child_process Issues and PRs related to the child_process subsystem. libuv Issues and PRs related to the libuv dependency or the uv binding. windows Issues and PRs related to the Windows platform.

Comments

@ilikesleeping
Copy link

ilikesleeping commented Aug 6, 2019

  • Version: v10.16.1
  • Platform: Windows 10 x64 Version 1803 (OS Build 17134.885)
  • Subsystem: child_process

When calling another process, the exec and execSync commands fail with a ENOMEM error when using an empty object for the options.env variable. Using any non-undefined value at all in the env object makes the call work again.

const { execSync } = require('child_process');
execSync('node', {env: {}}) // Fails with ENOMEM error
execSync('node', {env: {x: undefined}}) // Fails with ENOMEM error
execSync('node', {env: {x: 0}}) // Works

The error trace:

Thrown:
{ Error: spawnSync C:\WINDOWS\system32\cmd.exe ENOMEM
    at Object.spawnSync (internal/child_process.js:1002:20)
    at spawnSync (child_process.js:614:24)
    at execSync (child_process.js:661:13)
  errno: 'ENOMEM',
  code: 'ENOMEM',
  syscall: 'spawnSync C:\\WINDOWS\\system32\\cmd.exe',
  path: 'C:\\WINDOWS\\system32\\cmd.exe',
  spawnargs: [ '/d', '/s', '/c', '"node"' ],
  error: [Circular],
  status: null,
  signal: null,
  output: null,
  pid: 0,
  stdout: null,
  stderr: null }

This did not happen in v10.15.*, and seems to affect v10.16.0 as well.

@bnoordhuis bnoordhuis added child_process Issues and PRs related to the child_process subsystem. windows Issues and PRs related to the Windows platform. labels Aug 6, 2019
@addaleax
Copy link
Member

addaleax commented Aug 6, 2019

@nodejs/platform-windows

@targos
Copy link
Member

targos commented Aug 6, 2019

I confirm the behavior on Windows, with v12.7.0

bnoordhuis added a commit to bnoordhuis/libuv that referenced this issue Aug 6, 2019
Commit ba78023 ("unix,win: handle zero-sized allocations uniformly")
makes `uv__malloc()` return NULL when `size == 0`.

That's exactly the size that is passed to it when uv_spawn() tries to
spawn a process with an empty environment so handle that edge case.

Fixes: nodejs/node#29008
@bnoordhuis
Copy link
Member

libuv/libuv#2408 should fix that.

@bnoordhuis bnoordhuis added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Aug 6, 2019
bnoordhuis added a commit to bnoordhuis/libuv that referenced this issue Aug 9, 2019
Commit ba78023 ("unix,win: handle zero-sized allocations uniformly")
makes `uv__malloc()` return NULL when `size == 0`.

That's exactly the size that is passed to it when uv_spawn() tries to
spawn a process with an empty environment so handle that edge case.

Fixes: nodejs/node#29008
@richardlau
Copy link
Member

Reopening until the libuv update lands.

@richardlau richardlau reopened this Aug 9, 2019
cjihrig added a commit to cjihrig/node that referenced this issue Aug 11, 2019
Notable changes:

- UV_FS_O_FILEMAP has been added for faster access to memory
  mapped files on Windows.
- uv_fs_mkdir() now returns UV_EINVAL for invalid filenames
  on Windows. It previously returned UV_ENOENT.
- The uv_fs_statfs() API has been added.
- The uv_os_environ() and uv_os_free_environ() APIs have
  been added.

Fixes: nodejs#28599
Fixes: nodejs#28945
Fixes: nodejs#29008
PR-URL: nodejs#29070
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
targos pushed a commit that referenced this issue Aug 19, 2019
Notable changes:

- UV_FS_O_FILEMAP has been added for faster access to memory
  mapped files on Windows.
- uv_fs_mkdir() now returns UV_EINVAL for invalid filenames
  on Windows. It previously returned UV_ENOENT.
- The uv_fs_statfs() API has been added.
- The uv_os_environ() and uv_os_free_environ() APIs have
  been added.

Fixes: #28599
Fixes: #28945
Fixes: #29008
PR-URL: #29070
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
BethGriggs pushed a commit to BethGriggs/node that referenced this issue Feb 26, 2020
Notable changes:

- UV_FS_O_FILEMAP has been added for faster access to memory
  mapped files on Windows.
- uv_fs_mkdir() now returns UV_EINVAL for invalid filenames
  on Windows. It previously returned UV_ENOENT.
- The uv_fs_statfs() API has been added.
- The uv_os_environ() and uv_os_free_environ() APIs have
  been added.

Fixes: nodejs#28599
Fixes: nodejs#28945
Fixes: nodejs#29008
PR-URL: nodejs#29070
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
BethGriggs pushed a commit that referenced this issue Mar 2, 2020
Notable changes:

- UV_FS_O_FILEMAP has been added for faster access to memory
  mapped files on Windows.
- uv_fs_mkdir() now returns UV_EINVAL for invalid filenames
  on Windows. It previously returned UV_ENOENT.
- The uv_fs_statfs() API has been added.
- The uv_os_environ() and uv_os_free_environ() APIs have
  been added.

Fixes: #28599
Fixes: #28945
Fixes: #29008
PR-URL: #29070
Backport-PR-URL: #31969
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. libuv Issues and PRs related to the libuv dependency or the uv binding. windows Issues and PRs related to the Windows platform.
Projects
None yet
5 participants