Skip to content
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

Make sure we're connected before starting requests #2297

Merged
merged 4 commits into from
May 18, 2022

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented May 17, 2022

Fix #2295

After #2264, we now panic if starting a request on a peer we're not connected to because this is an invalid usage of the API.
The reason why this wouldn't panic before is because there was always a chance of a race condition where a connection started being closed in parallel of the request being started.
We simply do the check for connectivity in the network service, as it is now possible to do so.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
       -4320 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h20fa855eaeba7781
       +4249 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::he23e8f669d06410a
       +2482 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::he637c1eab989df1d
       -2288 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hdbeb5b06136a4651
       +2057 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h02ebbc1a8c3fe36a
       -2057 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hb4e6cdf6c98f96c7
       +1989 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h7da1dc845a0f3a54
       -1989 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::ha3320ff3528d18ea
       +1876 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h04428737906afac6
       -1876 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hdf3735eb1a9c3e5a
       -1701 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h0b605beeff9e6571
       +1701 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::ha897011ec92b406a
       +1508 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2f8dc18d2dc3d189
       +1503 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::he2c4234081f90694
       +1500 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h3185edd51271b344
       +1500 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hf016376d11266881
       +1497 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hb9ef990cff914aa6
       +1492 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h6c8797216e463e8c
       +1487 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h6a03727bc590cd0b
       +1472 ┊ <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h6749d1ddf8067f60
      -10219 ┊ ... and 394 more.
       +3609 ┊ Σ [414 Total Rows]

@@ -1171,6 +1171,20 @@ where
self.inner.respond_in_request(id.0, response)
}

/// Returns `true` if there exists an established connection with the given peer.
pub fn has_established_connection(&self, peer: &PeerId) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn has_established_connection(&self, peer: &PeerId) -> bool {
pub fn has_established_connection(&self, peer_id: &PeerId) -> bool {

None => return false,
};

self.connections_by_peer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we want to have multiple connections to the same peer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can happen accidentally if two peers connect to each other at the same time.

Another situation is if you connect to an IP address and expect to find peer A but actually connect to peer B, even though you're already connected to B.
In that case, from the point of view of peer B, maybe you have accidentally connected to it (the example that I just gave), but maybe the first connection you had with B is actually dead and you're reopening a new one.

The best way to handle these situations is to allow multiple connections between peers, and automatically close unused ones.

@@ -1919,6 +1919,11 @@ where
None
}

/// Returns `true` if there exists an established connection with the given peer.
pub fn has_established_connection(&self, peer: &PeerId) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn has_established_connection(&self, peer: &PeerId) -> bool {
pub fn has_established_connection(&self, peer_id: &PeerId) -> bool {

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label May 18, 2022
@mergify mergify bot merged commit 9a8a749 into paritytech:main May 18, 2022
@tomaka tomaka deleted the check-connec branch May 18, 2022 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic in Peers::start_request
2 participants