stream: add assertion against JDK bug to avoid spin loop in TlsActor (#30043)

* stream: add assertion against JDK bug to avoid spin loop in TlsActor

Refs #29922
This commit is contained in:
Johannes Rudolph 2021-03-10 08:49:15 +01:00 committed by GitHub
parent 4081638fd8
commit 0576acc1da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -368,10 +368,20 @@ import akka.util.ByteString
log.debug(
s"wrap: status=${result.getStatus} handshake=$lastHandshakeStatus remaining=${userInBuffer.remaining} out=${transportOutBuffer
.position()}")
if (lastHandshakeStatus == FINISHED) handshakeFinished()
runDelegatedTasks()
result.getStatus match {
case OK =>
// https://github.com/akka/akka/issues/29922
// It seems to be possible to get the SSLEngine into a state where
// result.getStatus == OK && getHandshakeStatus == NEED_WRAP but
// it doesn't make any progress any more.
//
// We guard against this JDK bug by checking for reasonable invariants after the call to engine.wrap
if (!(transportOutBuffer.position() > 0 || lastHandshakeStatus != NEED_WRAP))
throw new IllegalStateException("SSLEngine trying to loop NEED_WRAP without producing output")
flushToTransport()
userInChoppingBlock.putBack(userInBuffer)
case CLOSED =>