Skip to content

THRIFT-6158: Classify malformed request arguments as protocol errors - #3748

Merged
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-processor-protocol-errors
Aug 24, 2026
Merged

THRIFT-6158: Classify malformed request arguments as protocol errors#3748
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-processor-protocol-errors

Conversation

@kpumuk

@kpumuk kpumuk commented Aug 24, 2026

Copy link
Copy Markdown
Member

Malformed request arguments can raise a ProtocolException while a generated Ruby processor is decoding its argument structure. The processor currently handles that exception together with handler failures and returns INTERNAL_ERROR, making malformed protocol data appear to clients as a server-side failure.

This change marks protocol exceptions at the argument-reading boundary and returns an application exception with the PROTOCOL_ERROR type, preserving the original message, method name, and sequence ID. Protocol exceptions raised later by application handlers remain classified as INTERNAL_ERROR.

Benchmarks

The successful read_args path was measured on Ruby 4.0.6/aarch64-linux with one CPU pinned, a 500,000-call warmup, and 15 trials of 5,000,000 calls:

taskset -c 0 bundle exec ruby -e 'require "thrift"; class BenchProcessor; include Thrift::Processor; end; class BenchArgs; def read(_protocol); end; end; class BenchProtocol; def read_message_end; end; end; processor = BenchProcessor.new(Object.new, Logger.new(IO::NULL)); protocol = BenchProtocol.new; 500_000.times { processor.read_args(protocol, BenchArgs) }; samples = 15.times.map do; started = Process.clock_gettime(Process::CLOCK_MONOTONIC); 5_000_000.times { processor.read_args(protocol, BenchArgs) }; Process.clock_gettime(Process::CLOCK_MONOTONIC) - started; end; sorted = samples.sort; p samples; p sorted.fetch(7)'

Current master median: 0.786545 seconds
Proposed change median: 0.780384 seconds
Difference: -0.8%

This synthetic benchmark uses no-op argument and protocol objects to emphasize processor dispatch overhead; it excludes protocol decoding, transport, and network work. The difference is within run-to-run noise and shows no measurable regression.

  • Did you create an Apache Jira ticket? THRIFT-6158
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Client: rb

Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Copilot AI lite review requested due to automatic review settings August 24, 2026 13:15
@mergeable mergeable Bot added the ruby Pull requests that update Ruby code label Aug 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Ruby processor error handling so malformed request arguments (i.e., protocol decode failures while reading the generated args struct) are reported back to clients as Thrift::ApplicationException::PROTOCOL_ERROR instead of being lumped into INTERNAL_ERROR, while keeping protocol exceptions raised later by application handlers classified as internal errors.

Changes:

  • Introduces a private Thrift::Processor::ArgumentProtocolException wrapper raised only at the read_args boundary.
  • Updates Thrift::Processor#process to catch argument-decoding protocol failures and return an ApplicationException with type PROTOCOL_ERROR.
  • Adds specs covering both malformed-argument classification and handler-raised protocol exceptions remaining INTERNAL_ERROR.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/rb/lib/thrift/processor.rb Wraps ProtocolException from read_args and maps those to ApplicationException::PROTOCOL_ERROR in process.
lib/rb/spec/processor_spec.rb Adds coverage to ensure malformed request args produce PROTOCOL_ERROR, while handler-raised protocol exceptions remain INTERNAL_ERROR.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kpumuk
kpumuk merged commit 28d59c3 into apache:master Aug 24, 2026
93 of 94 checks passed
@kpumuk
kpumuk deleted the rb-processor-protocol-errors branch August 24, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Pull requests that update Ruby code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants