Skip to content

Commit 5361846

Browse files
authored
fix: Backport limit spin loop in TLSActor #29922 (#31975)
* fix: Try to limit spin loop in TLSActor #29922 Backport of fix from 2.8 release line. * Align header to make header check plugin happy
1 parent a646027 commit 5361846

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

akka-stream/src/main/scala/akka/stream/impl/io/TLSActor.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import akka.util.ByteString
6161

6262
import TLSActor._
6363

64+
private var unwrapPutBackCounter: Int = 0
6465
protected val outputBunch = new OutputBunch(outputCount = 2, self, this)
6566
outputBunch.markAllOutputs()
6667

@@ -354,6 +355,7 @@ import akka.util.ByteString
354355

355356
def flushToUser(): Unit = {
356357
if (tracing) log.debug("flushToUser")
358+
if (unwrapPutBackCounter > 0) unwrapPutBackCounter = 0
357359
userOutBuffer.flip()
358360
if (userOutBuffer.hasRemaining) {
359361
val bs = ByteString(userOutBuffer)
@@ -408,7 +410,17 @@ import akka.util.ByteString
408410
case OK =>
409411
result.getHandshakeStatus match {
410412
case NEED_WRAP =>
411-
flushToUser()
413+
// https://github.com/akka/akka/issues/29922
414+
// A second workaround for an infinite loop we have not been able to reproduce/isolate,
415+
// if you see this, and can reproduce consistently, please report back to the Akka team
416+
// with a reproducer or details about the client causing it
417+
unwrapPutBackCounter += 1
418+
if (unwrapPutBackCounter > 1000) {
419+
throw new IllegalStateException(
420+
s"Stuck in unwrap loop, bailing out, last handshake status [$lastHandshakeStatus], " +
421+
s"remaining=${transportInBuffer.remaining}, out=${userOutBuffer.position()}, " +
422+
"(https://github.com/akka/akka/issues/29922)")
423+
}
412424
transportInChoppingBlock.putBack(transportInBuffer)
413425
case FINISHED =>
414426
flushToUser()
@@ -480,7 +492,6 @@ import akka.util.ByteString
480492
pump()
481493
}
482494

483-
// FIXME: what happens if this actor dies unexpectedly?
484495
override def postStop(): Unit = {
485496
if (tracing) log.debug("postStop")
486497
super.postStop()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy