Exit ReadJsonFromInputStream if -1 byte is read

It was possible to get stuck in a loop reading -1 from the client
socket.
This commit is contained in:
Ethan Atkins 2020-06-28 19:09:03 -07:00
parent 3749678de3
commit 27c1978087
1 changed files with 10 additions and 7 deletions

View File

@ -57,6 +57,7 @@ private[sbt] object ReadJsonFromInputStream {
onCarriageReturn = false onCarriageReturn = false
consecutiveLineEndings += 1 consecutiveLineEndings += 1
case `carriageReturn` => onCarriageReturn = true case `carriageReturn` => onCarriageReturn = true
case -1 => running.set(false)
case c => case c =>
if (c == newline) getLine() if (c == newline) getLine()
else { else {
@ -66,14 +67,16 @@ private[sbt] object ReadJsonFromInputStream {
onCarriageReturn = false onCarriageReturn = false
consecutiveLineEndings = 0 consecutiveLineEndings = 0
} }
} while (consecutiveLineEndings < 2) } while (consecutiveLineEndings < 2 && running.get)
drainHeaders() drainHeaders()
val buf = new Array[Byte](len) if (running.get) {
var offset = 0 val buf = new Array[Byte](len)
do { var offset = 0
offset += inputStream.read(buf, offset, len - offset) do {
} while (offset < len) offset += inputStream.read(buf, offset, len - offset)
content = buf.toSeq } while (offset < len && running.get)
if (running.get) content = buf.toSeq
}
} }
} else if (line.startsWith("{")) { } else if (line.startsWith("{")) {
// Assume this is a json object with no headers // Assume this is a json object with no headers