Skip to content

fix(core): fix client crashes on large TLS responses#15

Merged
bluestreak01 merged 5 commits intomainfrom
fix/tls-unwrap-buffering
Apr 25, 2026
Merged

fix(core): fix client crashes on large TLS responses#15
bluestreak01 merged 5 commits intomainfrom
fix/tls-unwrap-buffering

Conversation

@sklarsa
Copy link
Copy Markdown
Contributor

@sklarsa sklarsa commented Apr 23, 2026

Summary

  • Fix JavaTlsClientSocket.recv() so a single TLS record larger than the caller's buffer no longer trips Output buffer too small to fit a single TLS record. Oversized plaintext is staged in an internal buffer and drained across subsequent recv() calls.
  • Fix recv() to keep unwrapping after SSLEngine.unwrap() returns OK with no plaintext produced (e.g. after a TLS 1.3 NewSessionTicket). The previous return 0 short-circuit left buffered records sitting in the input buffer and made callers like HttpClient.recvOrDie fall back to ioWait and time out despite having decryptable data on hand.
  • Preserve the zero-copy fast path: SSLEngine decrypts straight into the caller's buffer in the common case via a placeholder ByteBuffer repointed at recv() time. The internal spill buffer is used only when a single record does not fit, in which case it grows as needed.
  • Harden the same overflow paths during TLS handshake processing.
  • Add regression tests covering the empty-OK loop continuation, the spill-and-grow path, and the existing overflow-then-drain path; share SSLEngine stub boilerplate via a new StubSslEngine base.

Tooling

  • Add .claude/skills/review-pr/ so future /review-pr runs against this repo apply the same QuestDB review conventions used to vet the changes here.

Testing

  • JAVA_HOME=$(/usr/libexec/java_home -v 17) mvn -pl core test (1493 passing, 1 skipped)
  • JAVA_HOME=$(/usr/libexec/java_home -v 17) mvn -pl core -Dtest=JavaTlsClientSocketTest test

@sklarsa sklarsa force-pushed the fix/tls-unwrap-buffering branch from b287cb1 to cfae5fd Compare April 23, 2026 19:56
bluestreak01 and others added 2 commits April 25, 2026 20:24
recv() returned 0 from the OK branch whenever SSLEngine.unwrap
consumed input but produced no plaintext (for example after a
TLS 1.3 NewSessionTicket). The premature return left buffered
records sitting in the input buffer, so callers fell back to
ioWait and could time out despite having decryptable data on
hand. Keep looping instead so the next record is unwrapped.

While in there, restore the zero-copy fast path: SSLEngine now
decrypts straight into the caller's buffer through a placeholder
ByteBuffer repointed at recv() time. The internal buffer is used
only when a single TLS record does not fit in the caller's
buffer, in which case it grows as needed and any leftover
plaintext is drained on subsequent recv() calls.

Add tests for the empty-OK loop continuation, the spill-and-grow
path, and the existing overflow-then-drain path; share SSLEngine
stub boilerplate via a StubSslEngine base.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bluestreak01 bluestreak01 changed the title Fix TLS unwrap buffering for large reads fix(core): fix TLS unwrap buffering for large reads Apr 25, 2026
@bluestreak01 bluestreak01 changed the title fix(core): fix TLS unwrap buffering for large reads fix(core): fix client crashes on large TLS responses Apr 25, 2026
bluestreak01 and others added 2 commits April 25, 2026 21:10
Adds the /review-pr skill that performs a QuestDB-flavoured code
review of a GitHub PR: PR metadata, parallel correctness /
concurrency / performance / resource / test / quality / metadata /
Rust-safety agents, source-verification of every draft finding to
strip false positives, and a structured Critical / Moderate / Minor
report with a Downgraded section explaining dismissed findings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mtopolnik
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 38 / 57 (66.67%)

file detail

path covered line new line coverage
🔵 io/questdb/client/network/JavaTlsClientSocket.java 38 57 66.67%

@bluestreak01 bluestreak01 merged commit 0c7e9bb into main Apr 25, 2026
12 checks passed
@bluestreak01 bluestreak01 deleted the fix/tls-unwrap-buffering branch April 25, 2026 21:07
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