Skip to content

Fix spinloop bug in TLSEngine#3599

Merged
mpilquist merged 5 commits intotopic/net2from
topic/fix-spinloop-in-tlsengine
Sep 4, 2025
Merged

Fix spinloop bug in TLSEngine#3599
mpilquist merged 5 commits intotopic/net2from
topic/fix-spinloop-in-tlsengine

Conversation

@mpilquist
Copy link
Copy Markdown
Member

Fixes a spinloop bug where an aborted TLS handshake can result in TLSEngine consuming a CPU.

Initially reported by @matthughes.

binding.read(engine.getSession.getPacketBufferSize).flatMap {
case Some(c) => unwrapBuffer.input(c) >> unwrapHandshake
case None =>
unwrapBuffer.inputRemains
Copy link
Copy Markdown
Member Author

@mpilquist mpilquist Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we've reached this point, and there's data in unwrapBuffer, then we know the last handshake status was BUFFER_UNDERFLOW and we've read no data that can help progress the handshake.

Since binding.read has returned a None, we'll never get more data from the socket. Doing nothing will result in the infinite loop from the original bug report. To fix, we just terminate the handshake (via stopUnwrap).

@mpilquist mpilquist merged commit 39f1318 into topic/net2 Sep 4, 2025
33 checks passed
mpilquist added a commit that referenced this pull request Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants