Skip to content

THRIFT-6288: Clarify the message-size TODOs in the Rust protocols - #3880

Merged
Jens-G merged 1 commit into
apache:masterfrom
Jens-G:THRIFT-6288
Sep 17, 2026
Merged

Jens-G merged 1 commit into
apache:masterfrom
Jens-G:THRIFT-6288

Conversation

@Jens-G

@Jens-G Jens-G commented Sep 17, 2026

Copy link
Copy Markdown
Member

THRIFT-6288

Comment-only change: the three message-size TODOs in the Rust protocols now say what the code does today and why the more precise check is missing.

Background

The ticket quotes a TODO that is not the text in the tree. The actual comment in check_container_size, there since THRIFT-5871 (42d0b71), reads:

// TODO: When Rust trait specialization stabilizes, we can add more precise checks
// for transports that track exact remaining bytes. For now, we use the message
// size limit as a best-effort check.

That comment names a real obstacle. The THRIFT-5871 commit message says the same: full message-size tracking was left out because trait specialization is not stable.

  • TReadTransport is implemented for every io::Read by one blanket impl (transport/mod.rs). So no transport can supply its own remaining-bytes count without specialization or a change to the trait.
  • The other bindings keep that count in their transports, for example C++ TTransport and Java TEndpointTransport.

What the comment did not say is what the check compares against today, which is the whole max_message_size. It also did not say that up-front allocation does not depend on the check.

What changes

  • protocol/mod.rs, check_container_size: the TODO says that min_bytes_needed is held to the whole max_message_size rather than to what is left of the current message, and why. It also notes that generated code reserves list capacity through prealloc_size, which caps it; sets and maps are BTreeSet/BTreeMap and reserve nothing.
  • protocol/binary.rs and protocol/compact.rs, read_message_begin: the matching "call the message size tracking here" TODOs now say what would start there, and point to check_container_size.

No behaviour changes, so there is no test to add.

Verification

Rust 1.85.1, as in CI, in lib/rs:

  • cargo fmt --all -- --check, cargo clippy --all -- -D warnings and cargo clippy --all --all-features -- -D warnings are clean.
  • cargo check --no-default-features --features rustls passes.
  • cargo test and cargo test --all-features: 177 of 178 pass.
    • The one failure is transport::socket::tests::split_halves_must_not_clobber_each_others_timeout. It fails the same way on unmodified master on this machine: Some(252ms) vs Some(250ms).
    • The host kernel runs with CONFIG_HZ=250, and Linux stores socket timeouts in jiffies, so 250 ms comes back as 252 ms. The test passes in CI, so the runners' kernels keep 250 ms exact. The failure is unrelated to this change.
  • Merges cleanly with the open Rust PR THRIFT-6290: Rust: skip string/binary fields without heap-allocating #3854.

The change was written with AI assistance (Claude Opus 5), then reviewed and checked as described above.

🤖 Generated with Claude Code

Client: rs

The TODO in check_container_size did not say what the check compares
against today, or why the more precise check is missing. It holds the
smallest size a container's elements can take to the whole
max_message_size. The other bindings compare against what is left of the
current message, a count they keep in their transports. In Rust every
io::Read is a TReadTransport through one blanket impl, so a transport
cannot supply its own count until trait specialization is stable.

The comment now says that, and notes that up-front allocation does not
depend on the check. The two matching TODOs in read_message_begin point
to it. Comment-only change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mergeable mergeable Bot added the rust Pull requests that update Rust code label Sep 17, 2026
@Jens-G
Jens-G merged commit af4fa75 into apache:master Sep 17, 2026
101 of 102 checks passed
@Jens-G
Jens-G deleted the THRIFT-6288 branch September 17, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant