Skip to content

SSLSocket related improvements#351

Open
kares wants to merge 4 commits intomasterfrom
ssl-socket-fixes
Open

SSLSocket related improvements#351
kares wants to merge 4 commits intomasterfrom
ssl-socket-fixes

Conversation

@kares
Copy link
Member

@kares kares commented Mar 26, 2026

No description provided.

kares added 4 commits March 26, 2026 14:07
propagate exception flag through read() and readAndUnwrap()
`read==0` guard only called waitSelect when `status==BUFFER_UNDERFLOW`

after `readAndUnwrap` processes a TLS 1.3 NewSessionTicket (status=OK,
zero app bytes, no buffered network data), the guard was skipped causing
an unnecessary extra loop through `readAndUnwrap` before
`BUFFER_UNDERFLOW` was reached on the second pass
Cover normal (non-error) data flow through the code paths changed by
the read_nonblock exception fix and the netReadData.position() guard:

- Multi-chunk read_nonblock: 30KB echo in 1KB chunks (TLS 1.3 + 1.2)
- Multi-chunk with exception:false (TLS 1.3)
- Partial read_nonblock: read 5 bytes then remainder from appReadData
- Multiple puts/gets cycles: 10 rounds on a single connection
- sysread/syswrite round-trip: 3 blocking cycles with exact byte counts
- Large server write: server sends 48KB, client reads in 4KB chunks;
  regression test for netReadData.position()==0 guard (TLS 1.3 + 1.2)
write() unconditionally called netWriteData.clear() after a non-blocking
flushData() that may not have flushed all encrypted bytes.

This discarded unflushed TLS records, corrupting the encrypted stream
and causing 'Broken pipe' or 'Connection reset' errors on subsequent
writes — most commonly seen during 'gem push' of large gems over HTTPS.

Fix: replace clear() with compact() which preserves unflushed bytes by
moving them to the front of the buffer before engine.wrap() appends new
encrypted output.

Additionally, sysreadImpl() now flushes pending netWriteData before
reading.  After write_nonblock, encrypted bytes could remain unsent;
without flushing first the server would never receive the complete
request body (e.g. net/http POST), causing it to time out or reset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant