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

fix(terraform): prevent deadlock by consuming stdout #6037

Merged
merged 1 commit into from
May 14, 2024

Conversation

stefreak
Copy link
Member

@stefreak stefreak commented May 14, 2024

Nodejs spawn will cease to emit error or close events when stdout hasn't been consumed.

See also from official docs:

By default, pipes for stdin, stdout, and stderr are established between the parent Node.js process and the spawned subprocess. These pipes have limited (and platform-specific) capacity. If the subprocess writes to stdout in excess of that limit without the output being captured, the subprocess blocks waiting for the pipe buffer to accept more data. This is identical to the behavior of pipes in the shell. Use the { stdio: 'ignore' } option if the output will not be consumed.

Source: https://nodejs.org/api/child_process.html#optionsstdio

We used to consume the stdout, but in the ESM PR (0f535dd) we accidentally removed the pipe to logStream which can cause deadlocks for terraform users.

Nodejs spawn will cease to emit error or close events when stdout hasn't been consumed.

See also from official docs:

> By default, pipes for stdin, stdout, and stderr are established between the parent Node.js process and the spawned subprocess. These pipes have limited (and platform-specific) capacity. If the subprocess writes to stdout in excess of that limit without the output being captured, the subprocess blocks waiting for the pipe buffer to accept more data. This is identical to the behavior of pipes in the shell. Use the { stdio: 'ignore' } option if the output will not be consumed.

Source: https://nodejs.org/api/child_process.html#optionsstdio

We used to consume the stdout, but in the ESM PR (0f535dd) we accidentally removed the pipe to logStream which can cause deadlocks for terraform users.
@stefreak stefreak requested review from twelvemo and vvagaytsev May 14, 2024 10:12
Copy link
Collaborator

@vvagaytsev vvagaytsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! Amazing job on investigating this and drilling down to such low-level details! 🚀
Thank you for fixing this! 👍 💯

@stefreak stefreak enabled auto-merge May 14, 2024 10:41
@stefreak stefreak added this pull request to the merge queue May 14, 2024
@stefreak
Copy link
Member Author

@vvagaytsev thanks, hoping this is the sole culprit for the deadlocks we were seeing :)

Merged via the queue into main with commit 3640b4e May 14, 2024
40 checks passed
@stefreak stefreak deleted the fix/terraform-spawn-deadlock branch May 14, 2024 11:04
stefreak added a commit that referenced this pull request May 14, 2024
Follow-up on #6037 (This adds a missing test)
github-merge-queue bot pushed a commit that referenced this pull request May 14, 2024
@stefreak
Copy link
Member Author

regression test implemented in #6040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants