Skip to content

Commit

Permalink
fix(terraform): prevent deadlock by consuming stdout (#6037)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stefreak committed May 14, 2024
1 parent 809766f commit 3640b4e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/terraform/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export async function applyStack(params: TerraformParamsWithVariables) {
})
}

if (proc.stdout) {
proc.stdout.pipe(logStream)
}

logStream.on("data", (line: Buffer) => {
statusLine.info(styles.primary("→ " + line.toString()))
})
Expand Down

0 comments on commit 3640b4e

Please sign in to comment.