Skip to content

Commit

Permalink
req-resp: Fix panic on connection closed for substream open failure (#…
Browse files Browse the repository at this point in the history
…291)

When a new connection is reported to the request-response protocol, the
protocol tracks the state of the connection if and only if it could open
a substream with the remote peer.

We do not track the state of the connection in cases where the substream
cannot be opened because the connection is closed.

A further `ConnectionClosed` event triggered a debug_assert assumption
for this case. The assumption is wrong since opening substreams can fail
which informs us that the connection is closed.


Connection details not tracked:

https://github.com/paritytech/litep2p/blob/eed0f755d591eb49e1b715a78aceb5a653ddf529/src/protocol/request_response/mod.rs#L267-L284

Which later leads to panics:

https://github.com/paritytech/litep2p/blob/d6fae559fbe2aaf8cb3fff021fb5608ca7b43766/src/protocol/request_response/mod.rs#L295-L301



Related to: #290

---------

Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv authored Nov 27, 2024
1 parent d6fae55 commit eb0d6f2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
3 changes: 1 addition & 2 deletions src/protocol/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,8 @@ impl RequestResponseProtocol {
tracing::error!(
target: LOG_TARGET,
?peer,
"state mismatch: peer doesn't exist",
"Peer does not exist or substream open failed during connection establishment",
);
debug_assert!(false);
return;
};

Expand Down
1 change: 0 additions & 1 deletion src/protocol/request_response/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ async fn connection_closed_twice() {

#[tokio::test]
#[cfg(debug_assertions)]
#[should_panic]
async fn connection_established_twice() {
let (mut protocol, _handle, _manager, _tx) = protocol();

Expand Down

0 comments on commit eb0d6f2

Please sign in to comment.