镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Windows] process.stdin.unref doesn't work #22999

Description

  • Version: v10.10.0
  • Platform: Windows x64

parent.js

require('child_process').spawn('node', ['child.js'], {
  stdio: 'inherit',
});

child.js

const doNothing = () => {};
process.stdin.on('data', doNothing);

require('child_process').spawn('node', ['-v']).on('exit', () => {
  process.stdin.unref();
  console.log('After printing this, the process should exit');
});

Run with node parent.js

Results

Linux: The process terminates by itself
Mac: The process terminates by itself
Windows: The process keeps running until Enter is pressed

This strange behavior seems to break some npm modules.

Other details

Adding process.stdin.removeListener('data', doNothing)
or process.stdin.removeAllListeners('data')
before unref doesn't make any difference.

When enter is pressed, it doesn't trigger data callback, just terminates the process.


Edit

Simplified code:

// parent.js
process.stdin.on('data', () => {});
setTimeout(() => {
  process.stdin.unref();
  console.log('After printing this, the process should exit');
});

Here we don't have a child process. Run with node parent.js

Results on windows

50% of times - the process exits
50% of times - the process keeps running

Activity

  1. lovinglyy commented on Sep 22, 2018

    @lovinglyy
    Contributor

    The simplified code is always working fine for me, the first one I can reproduce that it's needed to press enter on Windows. Node v10.10.0 also.

  2. bzoz commented on Sep 24, 2018

    @bzoz
    Contributor

    Can reproduce with v10, does not reproduce with v8.

  3. bzoz commented on Sep 25, 2018

    @bzoz
    Contributor

    This is caused by #21528

    /cc @addaleax

  4. added
    windowsIssues and PRs related to the Windows platform.
    libuvIssues and PRs related to the libuv dependency or the uv binding.
    on Sep 25, 2018
  5. addaleax commented on Sep 25, 2018

    @addaleax
    Member

    That most likely means that the streams implementation for Windows does not clean up fully when uv_close() is used without an extra uv_read_stop() that precedes it.

    We can revert #21528 without any issues, but the real issue is almost certainly a libuv one.

  6. bzoz commented on Sep 26, 2018

    @bzoz
    Contributor

    Ok, its a libuv bug. I have a fix, I will open a PR with a fix soon.

  7. added a commit that references this issue on Sep 27, 2018
  8. bzoz commented on Sep 27, 2018

    @bzoz
    Contributor
  9. cjihrig commented on Sep 30, 2018

    @cjihrig
    Contributor

    Reopening until the next libuv update.

  10. added a commit that references this issue on Oct 8, 2018
  11. added a commit that references this issue on Oct 10, 2018
  12. added a commit that references this issue on Oct 17, 2018
  13. added a commit that references this issue on Jan 29, 2025
  14. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    libuvIssues and PRs related to the libuv dependency or the uv binding.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions