Skip to content

Fix of data loss issue during SSL communication#67

Merged
JavaSaBr merged 5 commits into
JavaSaBr:developfrom
crazyrokr:tls-support
May 16, 2026
Merged

Fix of data loss issue during SSL communication#67
JavaSaBr merged 5 commits into
JavaSaBr:developfrom
crazyrokr:tls-support

Conversation

@crazyrokr
Copy link
Copy Markdown
Contributor

@crazyrokr crazyrokr commented May 15, 2026

SSL Communication Fixes

  • Fixed data loss during SSL handshakes: In AbstractSslNetworkPacketReader, when the SSL engine status changed to NEED_WRAP but the network buffer still contained unprocessed data, that data could be lost. The reader now recursively calls decryptAndRead if the buffer has remaining bytes after a wrap request.
  • Prevented infinite loops: Added a safeguard in decryptAndRead to detect when no progress is made (zero bytes consumed and produced). In such cases, processing is halted to avoid potential dead loops.
  • Added comprehensive unit tests: Introduced AbstractSslNetworkPacketReaderTest with mocked SSLEngine to verify that:
    • No data is lost when NEED_WRAP occurs during a handshake.
    • The reader does not enter an infinite loop if decryption progress stalls.

Refactoring & Cleanup

  • Removed redundant code: Replaced AwaitUtils with Awaitility.
  • Updated Tests: Migrated ConnectionCloseTest to use JUnit 5's assertTimeoutPreemptively instead of the custom AwaitUtils.await method.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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: on NEED_WRAP, recurse into decryptAndRead if the buffer still has remaining bytes; in decryptAndRead, bail out on zero-progress OK results.
  • Adds AbstractSslNetworkPacketReaderTest covering the no-data-loss and no-dead-loop scenarios with a mocked SSLEngine.
  • Removes AwaitUtils and its tests; migrates ConnectionCloseTest to assertTimeoutPreemptively.

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.

Comment thread rlib-network/src/test/java/javasabr/rlib/network/ConnectionCloseTest.java Outdated
@crazyrokr crazyrokr requested a review from JavaSaBr May 16, 2026 12:04
@JavaSaBr JavaSaBr merged commit bd5b5f3 into JavaSaBr:develop May 16, 2026
1 of 2 checks passed
@github-actions
Copy link
Copy Markdown

Overall Project 54.43% -0.03% 🍏
Files changed 70.97% 🍏

File Coverage
AbstractSslNetworkPacketReader.java 50.64% -1.28% 🍏

@crazyrokr crazyrokr deleted the tls-support branch May 16, 2026 15:00
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.

3 participants