Interleaved stdout and stderr can attach multiline diagnostics to the wrong file
When a runner writes a multiline diagnostic across both stdout and stderr, the continuation lines can be attached to the wrong diagnostic.
I reproduced this locally on Windows with the repository at commit b814bdf31004ef7ed06ba7504b52fe96e3654f42. The test runner emitted the following records:
stdout:
a.go:1: error A
b.go:2: error B
stderr:
detail A
END
detail B
ENDUsing an errorformat with a multiline continuation and terminator, RunAndParse produced:
diag[0] path=a.go line=1 message="error A"
diag[1] path=b.go line=2 message="error B\ndetail A"The expected association is:
diag[0] path=a.go line=1 message="error A\ndetail A"
diag[1] path=b.go line=2 message="error B\ndetail B"The relative order of the two streams is lost in project/run.go. concurrentMultiReader copies stdout and stderr into separate buffers concurrently, then always copies the complete stdout buffer followed by the complete stderr buffer. This avoids the pipe deadlock described in the surrounding comments, but it also changes the input seen by the errorformat parser.
This can affect linters and compilers that split diagnostic headers and continuation lines between stdout and stderr. The resulting review comments or checks may contain details from another diagnostic and point reviewers at the wrong file or line.
A possible fix would be to consume the command output through a single ordered stream, or otherwise preserve the write order while retaining the current deadlock protection. A regression test covering interleaved multiline output would help prevent this from coming back.
Source: reviewdog/reviewdog