Fix of data loss issue during SSL communication#67
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes data loss during SSL handshake when the engine transitions to NEED_WRAP with unprocessed bytes still in the network buffer, adds a guard against infinite loops in decryptAndRead when no progress is made, and removes the now-unused AwaitUtils testing helper in favor of JUnit 5 timeout assertions.
Changes:
- In
AbstractSslNetworkPacketReader: onNEED_WRAP, recurse intodecryptAndReadif the buffer still has remaining bytes; indecryptAndRead, bail out on zero-progressOKresults. - Adds
AbstractSslNetworkPacketReaderTestcovering the no-data-loss and no-dead-loop scenarios with a mockedSSLEngine. - Removes
AwaitUtilsand its tests; migratesConnectionCloseTesttoassertTimeoutPreemptively.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| rlib-network/src/main/java/javasabr/rlib/network/packet/impl/AbstractSslNetworkPacketReader.java | Adds NEED_WRAP buffer-drain recursion and no-progress safeguard in decryption. |
| rlib-network/src/test/java/javasabr/rlib/network/packet/impl/AbstractSslNetworkPacketReaderTest.java | New tests verifying NEED_WRAP data preservation and dead-loop prevention. |
| rlib-network/src/test/java/javasabr/rlib/network/ConnectionCloseTest.java | Replaces AwaitUtils.await polling with assertTimeoutPreemptively; this replacement is not behavior-equivalent. |
| rlib-common/src/testFixtures/java/javasabr/rlib/common/util/AwaitUtils.java | Removes the AwaitUtils helper class. |
| rlib-common/src/test/java/javasabr/rlib/common/util/AwaitUtilsTest.java | Removes the corresponding test class. |
JavaSaBr
approved these changes
May 16, 2026
JavaSaBr
approved these changes
May 16, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SSL Communication Fixes
AbstractSslNetworkPacketReader, when the SSL engine status changed toNEED_WRAPbut the network buffer still contained unprocessed data, that data could be lost. The reader now recursively callsdecryptAndReadif the buffer has remaining bytes after a wrap request.decryptAndReadto detect when no progress is made (zero bytes consumed and produced). In such cases, processing is halted to avoid potential dead loops.AbstractSslNetworkPacketReaderTestwith mockedSSLEngineto verify that:NEED_WRAPoccurs during a handshake.Refactoring & Cleanup
AwaitUtilswithAwaitility.ConnectionCloseTestto use JUnit 5'sassertTimeoutPreemptivelyinstead of the customAwaitUtils.awaitmethod.