fix(provisioner/terraform): prevent deadlock when terraform emits log lines > 64 KiB#26238
Open
goingforstudying-ctrl wants to merge 1 commit into
Open
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
cdrci2
added a commit
to coder/cla
that referenced
this pull request
Jun 11, 2026
ba54328 to
d6c4f23
Compare
…ines Terraform providers (e.g. azurerm with TF_LOG=DEBUG) can emit single log lines that exceed the default 64 KiB bufio.MaxScanTokenSize. When this happens bufio.Scanner fails with 'token too long', the scanner loop exits, and the goroutine stops consuming from the io.Pipe. The pipe writer blocks, terraform's stdout/stderr block, and cmd.Wait() never returns, causing the provisioner to hang indefinitely with no error or timeout. Fix by: - Increasing the scanner buffer to 4 MiB via a newLogScanner helper. - Adding scanner.Err() handling in readAndLog and provisionReadAndLog so scan failures are surfaced as ERROR logs instead of silent deadlocks. - Adding a readLineWithFallback helper for future use with lines that may still exceed the enlarged buffer. Fixes coder/coder coder#24766
d6c4f23 to
f4f459a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ran into this while debugging an Azure deployment with TF_LOG=DEBUG set. The build would just hang forever — no error, no timeout, no progress. Took a while to figure out why.
The azurerm provider logs full HTTP response bodies (e.g. the subscription providers list, ~3 MB) as a single hclog [DEBUG] entry. That blows past bufio.Scanner's default 64 KiB limit. When scanner.Scan() fails with "token too long", the goroutine reading from the pipe exits, the pipe writer blocks, terraform's stdout/stderr block, and cmd.Wait() never returns. The provisioner is deadlocked.
I bumped the scanner buffer to 4 MiB and added scanner.Err() handling so any remaining failures get logged instead of causing silent hangs. Also added a fallback helper for truly enormous lines.
Fixes #24766
Not 100% sure about the 4 MiB constant — happy to adjust if there's a project preference.