Skip to content

Commit 92029e1

Browse files
authored
Fix race condition in cmdio.LogString (#3868)
## Changes Make `LogString` write the string and newline in a single call to reduce the likelihood of interleaved output when called concurrently. This was atomic until #3818 where I removed the lock, assuming it wasn't necessary. Note: This fix assumes `io.WriteString` provides atomic writes for small messages, which is not guaranteed. ## Why Fixes flaky test from: https://github.com/databricks/cli/actions/runs/18995883239/job/54255615389
1 parent aa9d438 commit 92029e1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

libs/cmdio/compat.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ func Log(ctx context.Context, str fmt.Stringer) {
2323
// It writes the string to the error writer.
2424
func LogString(ctx context.Context, str string) {
2525
c := fromContext(ctx)
26-
_, _ = io.WriteString(c.err, str)
27-
_, _ = io.WriteString(c.err, "\n")
26+
_, _ = io.WriteString(c.err, str+"\n")
2827
}
2928

3029
// readLine reads a line from the reader and returns it without the trailing newline characters.

0 commit comments

Comments
 (0)