Skip to content

Give each SSL call its own byte count - #88

Open
krynju wants to merge 1 commit into
JuliaWeb:mainfrom
krynju:kr/per-call-byte-counts
Open

krynju wants to merge 1 commit into
JuliaWeb:mainfrom
krynju:kr/per-call-byte-counts

Conversation

@krynju

@krynju krynju commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Split out of #73, as asked in the review there: an independent fix, against main.

Bug. readbytes, writebytes, peekbuf and peekbytes are Refs on the stream, shared by every task using it, and read back after @geterror has released ssl.lock. Another task's SSL call can overwrite the count in that gap. A writer that reads back a smaller count than its own thinks its chunk was not written and submits most of it again, duplicating plaintext on the wire; reads and peeks have the same hole. On main the gap is the lock release just before the read-back, so it needs threads to hit; any change that moves the socket write out from under the lock (the #72 fix) widens it to every parked write.

Fix. Each call allocates its own Refs. The four fields stay on the struct, unused by this package, since code outside it reads transport.readbytes[].

Test. ConcurrentWriters: four writers with different chunk sizes on one stream, the server checks every writer's bytes arrived exactly once. It passes on main on one thread, where the window cannot be hit, and guards the invariant from here on.

The test file gains the same three helpers as #86 (self-signed server context, handshake loop, connected pair), in the same place, so whichever lands later only has to re-append its testset.

No version bump; the fixes can be released together.

🤖 Generated with Claude Code

`readbytes`, `writebytes`, `peekbuf` and `peekbytes` are `Ref`s on the
stream, shared by every task using it, and read back after `@geterror`
released `ssl.lock`. Another task's SSL call can overwrite the count in
that gap: a writer reading back a smaller count than its own thinks its
chunk was not written and submits most of it again, duplicating
plaintext on the wire. Reads and peeks have the same hole.

The counts are per call now. The fields stay on the struct, unused by
this package, because code outside it reads `transport.readbytes[]`.

Adds `ConcurrentWriters`: four writers with different chunk sizes, the
server checks every writer's bytes arrived exactly once.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.96%. Comparing base (10f7b7b) to head (03d7af9).
⚠️ Report is 41 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   77.56%   78.96%   +1.39%     
==========================================
  Files           2        2              
  Lines        1083     1193     +110     
==========================================
+ Hits          840      942     +102     
- Misses        243      251       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant