THRIFT-6158: Classify malformed request arguments as protocol errors - #3748
Merged
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Contributor
There was a problem hiding this comment.
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::ArgumentProtocolExceptionwrapper raised only at theread_argsboundary. - Updates
Thrift::Processor#processto catch argument-decoding protocol failures and return anApplicationExceptionwith typePROTOCOL_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Malformed request arguments can raise a
ProtocolExceptionwhile a generated Ruby processor is decoding its argument structure. The processor currently handles that exception together with handler failures and returnsINTERNAL_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_ERRORtype, preserving the original message, method name, and sequence ID. Protocol exceptions raised later by application handlers remain classified asINTERNAL_ERROR.Benchmarks
The successful
read_argspath 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: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.
[skip ci]anywhere in the commit message to free up build resources.