Skip to content

Commit

Permalink
Return span in InFlightRequests::complete_request.
Browse files Browse the repository at this point in the history
Rather than returning a bool, return the Span associated with the
request. This gives RequestDispatch more flexibility to annotate the
request span.
  • Loading branch information
tikue committed Dec 29, 2023
1 parent 8dc3711 commit 84932df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 7 additions & 2 deletions tarpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,15 @@ where

/// Sends a server response to the client task that initiated the associated request.
fn complete(mut self: Pin<&mut Self>, response: Response<Resp>) -> bool {
self.in_flight_requests().complete_request(
if let Some(span) = self.in_flight_requests().complete_request(
response.request_id,
response.message.map_err(RpcError::Server),
)
) {
let _entered = span.enter();
tracing::info!("ReceiveResponse");
return true;
}
false
}
}

Expand Down
8 changes: 3 additions & 5 deletions tarpc/src/client/in_flight_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,18 @@ impl<Res> InFlightRequests<Res> {
}

/// Removes a request without aborting. Returns true iff the request was found.
pub fn complete_request(&mut self, request_id: u64, result: Res) -> bool {
pub fn complete_request(&mut self, request_id: u64, result: Res) -> Option<Span> {
if let Some(request_data) = self.request_data.remove(&request_id) {
let _entered = request_data.span.enter();
tracing::info!("ReceiveResponse");
self.request_data.compact(0.1);
self.deadlines.remove(&request_data.deadline_key);
let _ = request_data.response_completion.send(result);
return true;
return Some(request_data.span);
}

tracing::debug!("No in-flight request found for request_id = {request_id}.");

// If the response completion was absent, then the request was already canceled.
false
None
}

/// Completes all requests using the provided function.
Expand Down

0 comments on commit 84932df

Please sign in to comment.