Skip to content

Workers only pipe one message to stdout before they stop running #53701

Open
@realriccio

Description

@realriccio

Version

22.4.0 (i also tried earlier versions and the bug is always present)

Platform

Both in Linux and Windows, all OS versions.

Subsystem

worker_threads

What steps will reproduce the bug?

const { Worker } = require("worker_threads");

let worker = new Worker(`function print_three_and_work(){
	console.log("a");
	console.log("b");
	console.log("c");

	while(true){}
}

print_three_and_work();`, {eval: true});

or

const { Worker } = require("worker_threads");

let worker = new Worker(`function print_three_and_work(){
	console.log("a");
	console.log("b");
	console.log("c");

	while(true){}
}

print_three_and_work();`, {eval: true, stdout: true});

worker.stdout.on("data", function(chunk){
	process.stdout.write(chunk);
});

How often does it reproduce? Is there a required condition?

It always happens.

What is the expected behavior? Why is that the expected behavior?

All logged messages should be piped to the main thread's stdout while the worker is running.

What do you see instead?

Only the first message is piped. All other messages are not piped while the worker is running. They get piped all at once once the worker stops running.

(I see "a" instead of seeing "a \n b \n c".)

Additional information

#40961

I believe this other issue has a similar problem but it was misunderstood as having something to do with "process.exit", while instead it must be because of something else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    workerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions