Hold lock while writing bytes to stdout

We should always hold the print stream lock when calling
progressState.write because otherwise the task progress thread could
concurrently write to stdout.
This commit is contained in:
Ethan Atkins 2020-07-25 14:32:38 -07:00
parent 44a605198b
commit e4cd6a38fc
1 changed files with 3 additions and 2 deletions

View File

@ -882,8 +882,9 @@ object Terminal {
}
override def flush(): Unit = combinedOutputStream.flush()
}
private def doWrite(bytes: Array[Byte]): Unit =
progressState.write(TerminalImpl.this, bytes, rawPrintStream, hasProgress.get && !rawMode.get)
private def doWrite(bytes: Array[Byte]): Unit = withPrintStream { ps =>
progressState.write(TerminalImpl.this, bytes, ps, hasProgress.get && !rawMode.get)
}
override private[sbt] val printStream: PrintStream = new LinePrintStream(outputStream)
override def inputStream: InputStream = writeableInputStream