Skip to content

process.on beforeExit broken on Windows #9067

Closed
@joaocgreis

Description

@joaocgreis
  • Version: all >=4.0.0
  • Platform: Windows
  • Subsystem: v8, lib (?)

Investigating #8821 (comment) , I found that process.on('beforeExit', ...) is broken on Windows if node is not invoked from the Windows Command Prompt. Here is a simple repro:

const child = require('child_process');
//const script = "console.log('start');"; // OK
//const script = "process.on('exit', () => console.log('exit')); console.log('start');"; // OK
const script = "process.on('beforeExit', () => console.log('beforeExit')); console.log('start');";
const proc = child.spawn(process.execPath, ['-e', script], { encoding: 'utf8' });
proc.stdout.on('data', (data) => console.log(`stdout: ${data}`));
proc.stderr.on('data', (data) => console.log(`stderr: ${data}`));

This triggers an infinite loop printing beforeExit to stdout. This happens when node spawns itself (as in the repro above) or when node is started from gitbash. This does not happen when node is started from the Windows Command Prompt with

node -e "process.on('beforeExit', () => console.log('beforeExit')); console.log('start')"

but happens with

node -e "process.on('beforeExit', () => console.log('beforeExit')); console.log('start')" | cat

so it might be related to output redirection or output not being a TTY.

Bisected, first bad commit is c431725 (V8 4.5 update before node v4.0.0).

cc @nodejs/platform-windows @bnoordhuis

Metadata

Metadata

Assignees

No one assigned

    Labels

    processIssues and PRs related to the process subsystem.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