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.
Arcp::Client#requestsends the outbound envelope before registering the pending waiter.lib/arcp/client.rb:237callssend_envelope, thenlib/arcp/client.rb:238throughlib/arcp/client.rb:239creates 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@pendingcontains the request id, drop the response, and leave the caller blocked onqueue.dequeue. A related nil handling problem exists inget_result: whendrain_streamswakes result waiters with nil after transport close,lib/arcp/client.rb:182callsenv.typeand raisesNoMethodErrorinstead 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_toand remove the fallback type match if it can misdeliver concurrent same-type requests. Inget_result, handle a nil dequeue the same wayrequestdoes and raise a typedArcp::Errors::ProtocolViolationor retryable transport error. Add concurrency-oriented tests with two simultaneous requests and a closed transport waiting onget_result.