THRIFT-6107: Preserve NonblockingServer reply order#3648
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.4) <codex@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a correctness issue in the Ruby Thrift::NonblockingServer where replies on a single connection could be written out of order when requests are dispatched to different worker threads and later handlers finish first. It introduces a per-connection ordered response queue so replies are only published in contiguous request sequence order, while keeping independent connections concurrent.
Changes:
- Add a per-connection
IOManager::ResponseQueuethat reserves request sequence IDs, bounds in-flight work, and publishes completed responses in order. - Update
IOManager/Workerflow so workers write responses into an in-memory buffer and the response queue serializes writes to the underlying connection transport. - Expand Ruby specs to validate ordered reply publication and cover edge cases (oneway handling, failures, disconnect/cleanup, capacity/backpressure).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/rb/spec/nonblocking_server_spec.rb | Adds end-to-end and unit-level specs validating in-order replies per connection and response-queue edge cases. |
| lib/rb/lib/thrift/server/nonblocking_server.rb | Implements per-connection response ordering, buffering, and capacity signaling within NonblockingServer::IOManager. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewFound 1 issue:
thrift/lib/rb/lib/thrift/server/nonblocking_server.rb Lines 438 to 461 in d8da61a thrift/lib/rb/lib/thrift/server/nonblocking_server.rb Lines 497 to 504 in d8da61a 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Ruby's
NonblockingServercan dispatch multiple requests from one connection to different workers. When a later handler finishes first, it can write its reply before an earlier request’s reply, which breaks clients that intentionally pipeline requests on that connection.This change gives each connection an ordered response queue. A completed reply waits until all earlier request sequences have been published; oneway calls, handler failures, write failures, connection removal, and shutdown advance or discard the affected queue safely. Requests on separate connections continue to run independently.
[skip ci]anywhere in the commit message to free up build resources.