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-08-09 16:33:46 -07:00
parent 44a605198b
commit e4cd6a38fc
@@ -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