mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
main: synchronize writes to VT100-faker on Windows
We use a third-party library "colorable" to translate VT100 color sequences into Windows console attribute-setting calls when Terraform is running on Windows. colorable is not concurrency-safe for multiple writes to the same console, because it writes to the console one character at a time and so two concurrent writers get their characters interleaved, creating unreadable garble. Here we wrap around it a synchronization mechanism to ensure that there can be only one Write call outstanding across both stderr and stdout, mimicking the usual behavior we expect (when stderr/stdout are a normal file handle) of each Write being completed atomically.
This commit is contained in:
9
main.go
9
main.go
@@ -258,6 +258,15 @@ func copyOutput(r io.Reader, doneCh chan<- struct{}) {
|
||||
if runtime.GOOS == "windows" {
|
||||
stdout = colorable.NewColorableStdout()
|
||||
stderr = colorable.NewColorableStderr()
|
||||
|
||||
// colorable is not concurrency-safe when stdout and stderr are the
|
||||
// same console, so we need to add some synchronization to ensure that
|
||||
// we can't be concurrently writing to both stderr and stdout at
|
||||
// once, or else we get intermingled writes that create gibberish
|
||||
// in the console.
|
||||
wrapped := synchronizedWriters(stdout, stderr)
|
||||
stdout = wrapped[0]
|
||||
stderr = wrapped[1]
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
Reference in New Issue
Block a user