Skip to content

Commit 998425a

Browse files
committed
request_response: Add debug information for active requests
1 parent 5151975 commit 998425a

File tree

1 file changed

+52
-6
lines changed
  • src/protocol/request_response

1 file changed

+52
-6
lines changed

src/protocol/request_response/mod.rs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ impl RequestResponseProtocol {
312312

313313
// sent failure events for all pending outbound requests
314314
for request_id in context.active {
315+
tracing::debug!(
316+
target: LOG_TARGET,
317+
?peer,
318+
protocol = %self.protocol,
319+
?request_id,
320+
"removing request_id from active due to peer disconnect",
321+
);
315322
let _ = self
316323
.event_tx
317324
.send(InnerRequestResponseEvent::RequestFailed {
@@ -627,10 +634,25 @@ impl RequestResponseProtocol {
627634
if let Some(context) = self.pending_dials.remove(&peer) {
628635
tracing::debug!(target: LOG_TARGET, ?peer, protocol = %self.protocol, "failed to dial peer");
629636

630-
let _ = self
631-
.peers
632-
.get_mut(&peer)
633-
.map(|peer_context| peer_context.active.remove(&context.request_id));
637+
let Some(peer_context) = self.peers.get_mut(&peer) else {
638+
tracing::debug!(
639+
target: LOG_TARGET,
640+
?peer,
641+
"failed to get peer context on dial failure",
642+
);
643+
return;
644+
};
645+
646+
let removed = peer_context.active.remove(&context.request_id);
647+
tracing::debug!(
648+
target: LOG_TARGET,
649+
?peer,
650+
protocol = %self.protocol,
651+
request_id = ?context.request_id,
652+
removed,
653+
"removed request_id from active (on dial failure)",
654+
);
655+
634656
let _ = self
635657
.report_request_failure(
636658
peer,
@@ -672,12 +694,21 @@ impl RequestResponseProtocol {
672694
"failed to open substream",
673695
);
674696

675-
let _ = self
697+
let removed = self
676698
.peers
677699
.get_mut(&peer)
678700
.map(|peer_context| peer_context.active.remove(&request_id));
701+
tracing::debug!(
702+
target: LOG_TARGET,
703+
?peer,
704+
protocol = %self.protocol,
705+
?request_id,
706+
removed,
707+
"removed request_id from active (on substream open failure)",
708+
);
679709

680-
self.event_tx
710+
let _ = self
711+
.event_tx
681712
.send(InnerRequestResponseEvent::RequestFailed {
682713
peer,
683714
request_id,
@@ -779,6 +810,13 @@ impl RequestResponseProtocol {
779810
match self.service.open_substream(peer) {
780811
Ok(substream_id) => {
781812
let unique_request_id = context.active.insert(request_id);
813+
tracing::debug!(
814+
target: LOG_TARGET,
815+
?peer,
816+
protocol = %self.protocol,
817+
?request_id,
818+
"inserted request_id into active",
819+
);
782820
debug_assert!(unique_request_id);
783821

784822
self.pending_outbound.insert(
@@ -826,6 +864,14 @@ impl RequestResponseProtocol {
826864
"invalid state: received substream event but no active substream",
827865
);
828866
return Err(Error::InvalidState);
867+
} else {
868+
tracing::debug!(
869+
target: LOG_TARGET,
870+
?peer,
871+
protocol = %self.protocol,
872+
?request_id,
873+
"removed request_id from active (on substream event)",
874+
);
829875
}
830876

831877
let event = match message {

0 commit comments

Comments
 (0)