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

transport: Abort canceled dial attempts for TCP, WebSocket and Quic #255

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lexnv
Copy link
Collaborator

@lexnv lexnv commented Sep 25, 2024

The TransportManager initiates a dialing process on multiple addresses and multiple transports (ie TCP WebSocket).
The first established connection is reported back from the Transport layer to the TransportManger.
Then, the Transport Manager cancels all ongoing dialing attempts on the remaining layers.

Previously, cancelling implies storing a ConnectionID to a HashSet.
This has the downside that all ongoing dial attempts are polled to completion.

In this PR, the futures that establish socket connections are now aborted directly.

Example

Manager ---> TCP (dial address A, B, C)
        ---> WebSocket ( dial address D, E, F)

T0. Manager initiates dialing on A, B, C for TCP and D, E, F on WebSocket
T1. Established socket connection on address A from TCP (B and C are dropped)
T2. Manager cancels D, E, F from WebSocket

Before

T2 implies adding a connectionID to a hashset:

fn cancel(&mut self, connection_id: ConnectionId) {
self.canceled.insert(connection_id);

The worst case scenario:

  • wait for all D, E, F to establish connection, then emit back event to manager if the connection ID was not canceled
    The best case scenario:
  • wait for one of D, E, F to establish connection, then emit back event to manager if the connection ID was not canceled

if !self.canceled.remove(&connection_id) {
self.opened_raw.insert(connection_id, (stream, address.clone()));
return Poll::Ready(Some(TransportEvent::ConnectionOpened {
connection_id,
address,
}));

After

The future that handles dialing is abortable. This way, we don't have to wait for (worst case) all addresses to fail to connect, or (best case) one address to connect.

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv added the enhancement New feature or request label Sep 25, 2024
@lexnv lexnv self-assigned this Sep 25, 2024
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv changed the title transport: Abort canceled dial attempts for TCP and WebSocket transport: Abort canceled dial attempts for TCP, WebSocket and Quic Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant