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

Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSize #33666

Closed
arciisine opened this issue May 31, 2020 · 3 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. worker Issues and PRs related to Worker support.

Comments

@arciisine
Copy link

  • Version:
    Node v14.2
  • Platform:
    Linux
  • Subsystem:
    Ubuntu 20.04

What steps will reproduce the bug?

Spawn a worker thread that is meant to interact with the CLI. The spawned worker's process.stdout will not have a columns property nor getWindowSize.

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

100%

What is the expected behavior?

I would expect to have access to the dimensions of the parent stdout within the worker thread.

What do you see instead?

Within the worker thread, process.stdout.columns is undefined, as is getWindowSize

Additional information

When spawning a worker thread that is responsible for interacting with the CLI, tools will rely upon the dimensions of stdout for calculating bounds. Currently I'm working around this by passing the existing dimensions as an environment variable, and then patching them onto the worker's stdout on load.

@arciisine arciisine changed the title Worker Threads do not preserve process.stdout.columns or have access to process.stdout.getWindowSize Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSize May 31, 2020
@arciisine arciisine changed the title Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSize Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSize May 31, 2020
@addaleax addaleax added the worker Issues and PRs related to Worker support. label May 31, 2020
@addaleax
Copy link
Member

I would consider this expected behavior. Worker threads don’t spawn with the same stdio streams as parent threads, but instead they pass the data between themselves and the main thread, similar to a pipe when spawning child processes.

Partially, this is because of a restriction in libuv that multiple threads can’t share access to the same file descriptor.

When spawning a worker thread that is responsible for interacting with the CLI

Worker threads are designed to offload CPU-intensive tasks off the main thread, and not really for more than that, at least currently. It sounds like you’re doing something that might better not be implemented as a worker thread?

@arciisine
Copy link
Author

I concur this isn't a great fit. I would honestly rather fork, but given that forking in node is just spawning a new process, I was trying to avoid the extra overhead. I would say though, that the flags for redirecting stdout from the worker to the parent's stdout, have a gap due to this issue.

If the desire is for proper formatting, I'm assuming that the child worker should never be outputting directly the process' stdout. Given this limitation and the limitations listed above, it seems like stdio from the child to the parent should generally be discouraged, and used in only the most trivial cases.

@bnoordhuis
Copy link
Member

Thanks for the report. I think this is in broad strokes a duplicate of #26946. #26946 (comment) in particular applies and notes have been added to the documentation since.

I'll go ahead and close this out but let me know if there's still anything actionable on our side.

@bnoordhuis bnoordhuis added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. worker Issues and PRs related to Worker support.
Projects
None yet
Development

No branches or pull requests

3 participants