Skip to content

THRIFT-6281: Hold the frames TFramedTransport writes to the configured frame size - #3873

Open
Jens-G wants to merge 1 commit into
apache:masterfrom
Jens-G:THRIFT-6281
Open

Jens-G wants to merge 1 commit into
apache:masterfrom
Jens-G:THRIFT-6281

Conversation

@Jens-G

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

Copy link
Copy Markdown
Member

JIRA: THRIFT-6281
Client: go

TFramedTransport.Flush checked a frame against math.MaxUint32 only. readFrame refuses a frame larger than the configured MaxFrameSize (default 16384000), but Flush wrote such frames. Measured on master with MaxFrameSize: 1024: Flush of a 2048-byte frame returned nil and wrote 2052 bytes, and a TFramedTransport with the same configuration refused that frame with "Incorrect frame size (2048)".

This is the plain framed counterpart of #3860 (THRIFT-6262), which does the same for THeaderTransport.

Change

  • Flush applies GetMaxFrameSize(). A larger frame is refused with a TTransportException, like the existing checks in this file, and nothing of it is written.
  • GetMaxFrameSize() never exceeds math.MaxInt32, so the new check also covers the old MaxUint32 one.
  • The defer that returns the write buffer now runs before the check, so a refused frame is dropped. The next Write/Flush starts from an empty buffer rather than failing again on the same oversized one.
  • lib/go/README.md gets a note for clients that send frames larger than the default. The note sits before the TLS section, so it does not collide with the one THRIFT-6262: Hold the frames THeaderTransport writes to the configured frame size #3860 appends.

Compatibility

A client that writes frames larger than its own MaxFrameSize now gets an error from Flush instead of sending a frame that a peer with the same configuration refuses.

Tests

New TestTFramedTransportFlushFrameSizeLimit:

  • At the limit: a frame of exactly the limit is written and read back.
  • One byte over: Flush returns a TTransportException and writes 0 bytes. The next small frame then goes out on its own, 4 + 4 bytes.

Results:

  • Unmodified library: the over-limit case fails, because Flush returned nil.
  • Mutations: each fails one assertion:
    • >>=;
    • removing the check;
    • moving the buffer release back behind the check.
  • Checks: go vet -stdmethods=false and go test -race ./thrift pass with Go 1.26 and 1.27, and GOARCH=386 vet and tests pass as well.

🤖 Generated with Claude Code

…d frame size

Client: go

TFramedTransport.Flush checked a frame against math.MaxUint32 only, so it
wrote frames larger than the transport's MaxFrameSize, which readFrame
refuses. Flush now applies the configured maximum and returns a
TTransportException before writing any part of a larger frame. The maximum
is below what the 32-bit length can carry, so the old check is covered by
it. The refused frame is dropped with the write buffer, so the transport
stays usable for the next one.

lib/go/README.md notes the change for clients that send frames larger than
the default.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Jens-G
Jens-G requested a review from fishy as a code owner September 16, 2026 21:52
@mergeable mergeable Bot added the golang Pull requests that update Go code label Sep 16, 2026
// readFrame refuses a frame larger than the configured maximum, and so does
// a peer holding the same configuration. The maximum is below what the
// 32-bit length can carry. A refused frame is dropped with the buffer.
if maxSize := p.cfg.GetMaxFrameSize(); int64(size) > int64(maxSize) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we reuse the same helper in THeader implementation? in that helper we also checked against MaxUint32 which we didn't do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

golang Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants