Skip to content

Harden client waiters against response races and closed transports #32

@nficano

Description

@nficano

Arcp::Client#request sends the outbound envelope before registering the pending waiter. lib/arcp/client.rb:237 calls send_envelope, then lib/arcp/client.rb:238 through lib/arcp/client.rb:239 creates and records the queue that the reader loop uses to match replies. On a fast transport or under scheduler interleaving, the reader can dispatch the reply before @pending contains the request id, drop the response, and leave the caller blocked on queue.dequeue. A related nil handling problem exists in get_result: when drain_streams wakes result waiters with nil after transport close, lib/arcp/client.rb:182 calls env.type and raises NoMethodError instead of an ARCP transport or protocol error.

Fix prompt: Register pending waiters before any operation that can let the peer reply, or split envelope construction from transport send so the request id is known before sending. Make reply matching prefer reply_to and remove the fallback type match if it can misdeliver concurrent same-type requests. In get_result, handle a nil dequeue the same way request does and raise a typed Arcp::Errors::ProtocolViolation or retryable transport error. Add concurrency-oriented tests with two simultaneous requests and a closed transport waiting on get_result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:mediumMedium severity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions