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