litep2p icon indicating copy to clipboard operation
litep2p copied to clipboard

Handle dial `AlreadyConnected` error via retries or state modification

Open lexnv opened this issue 5 months ago • 0 comments

Because of the async nature of our code, it is entirely possible that:

  • we try to dial a peer that is already connected
  • the dialing happens before a ConnectionEstablished event is received

At the moment, this is affecting the request-response and notification protocols. Instead of returning an immediate error, try to cache the request or state of negotiation and submit it when the connection is reported via events.

Code examples: https://github.com/paritytech/litep2p/blob/10aa306c6ce255b154d69d5a73f45b39080a1e98/src/protocol/request_response/mod.rs#L728

https://github.com/paritytech/litep2p/blob/10aa306c6ce255b154d69d5a73f45b39080a1e98/src/protocol/notification/mod.rs#L937

Discovered during: https://github.com/paritytech/litep2p/pull/222

lexnv avatar Aug 30 '24 10:08 lexnv