Skip to content

request_response: Add debug information for active requests #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions src/protocol/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ impl RequestResponseProtocol {

// sent failure events for all pending outbound requests
for request_id in context.active {
tracing::debug!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
?request_id,
"removing request_id from active due to peer disconnect",
);
let _ = self
.event_tx
.send(InnerRequestResponseEvent::RequestFailed {
Expand Down Expand Up @@ -627,10 +634,25 @@ impl RequestResponseProtocol {
if let Some(context) = self.pending_dials.remove(&peer) {
tracing::debug!(target: LOG_TARGET, ?peer, protocol = %self.protocol, "failed to dial peer");

let _ = self
.peers
.get_mut(&peer)
.map(|peer_context| peer_context.active.remove(&context.request_id));
let Some(peer_context) = self.peers.get_mut(&peer) else {
tracing::debug!(
target: LOG_TARGET,
?peer,
"failed to get peer context on dial failure",
);
return;
};

let removed = peer_context.active.remove(&context.request_id);
tracing::debug!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
request_id = ?context.request_id,
removed,
"removed request_id from active (on dial failure)",
);

let _ = self
.report_request_failure(
peer,
Expand Down Expand Up @@ -672,12 +694,21 @@ impl RequestResponseProtocol {
"failed to open substream",
);

let _ = self
let removed = self
.peers
.get_mut(&peer)
.map(|peer_context| peer_context.active.remove(&request_id));
tracing::debug!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
?request_id,
removed,
"removed request_id from active (on substream open failure)",
);

self.event_tx
let _ = self
.event_tx
.send(InnerRequestResponseEvent::RequestFailed {
peer,
request_id,
Expand Down Expand Up @@ -779,6 +810,13 @@ impl RequestResponseProtocol {
match self.service.open_substream(peer) {
Ok(substream_id) => {
let unique_request_id = context.active.insert(request_id);
tracing::debug!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
?request_id,
"inserted request_id into active",
);
debug_assert!(unique_request_id);

self.pending_outbound.insert(
Expand Down Expand Up @@ -826,6 +864,14 @@ impl RequestResponseProtocol {
"invalid state: received substream event but no active substream",
);
return Err(Error::InvalidState);
} else {
tracing::debug!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
?request_id,
"removed request_id from active (on substream event)",
);
}

let event = match message {
Expand Down
Loading