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

feat(quic): Wake transport when adding a new dialer or listener #3342

Merged
merged 12 commits into from
Jan 23, 2023

Conversation

elenaf9
Copy link
Contributor

@elenaf9 elenaf9 commented Jan 17, 2023

Description

Wake quic::GenTransport if a new dialer or listener is added.

Notes

This re-adds #3306 with the solution initially drafted by @mxinden for waking the transport if a new dialer is added.
I added to also wake the transport if a new listener was pushed. The SelectAll around the listeners itself doesn't wake the task if a new element is pushed. This is not a major problem since the user would call poll again after a listen_on call and thus registering a new waker, but it solves the edge cast of a user doing something like this:

match quic_transport.poll_next(cx) {
   Poll::Ready(event) => return event,
   Poll::Pending => {}
}
quic_transport.listen_on(addr);
return Poll::Pending

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • .A changelog entry has been made in the appropriate crates

mxinden and others added 6 commits January 13, 2023 16:56
Scenario: rust-libp2p node A dials rust-libp2p node B. B listens on a QUIC
address. A dials B via the `libp2p-quic` `Transport` wrapped in a `libp2p-dns`
`Transport`.

Note that `libp2p-dns` in itself is not relevant here. Only the fact that
`libp2p-dns` delays a dial is relevant, i.e. that it first does other async
stuff (DNS lookup) before creating the QUIC dial. In fact, dialing an IP address
through the DNS `Transport` where no DNS resolution is needed triggers the below
just fine.

1. A calls `Swarm::dial` which creates a `libp2p-dns` dial.
2. That dial is spawned onto the connection `Pool`, thus starting the DNS
   resolution.
3. A continuously calls `Swarm::poll`.
4. `libp2p-quic` `Transport::poll` is called, finding no dialers in
   `self.dialer` given that the spawned dial is still only resolving the DNS
   address.
5. On the spawned connection task:
  1. The DNS resolution finishes.
  2. Thus calling `Transport::dial` on `libp1p-quic` (note that the DNS dial has
     a clone of the QUIC `Transport` wrapped in an `Arc<Mutex<_>>`).
  3. That adds a dialer to `self.dialer`. Note that there are no listeners, i.e.
     `Swarm::listen_on` was never called.
  4. `DialerState::new_dial` is called which adds a message to
     `self.pending_dials` and wakes `self.waker`. Given that on the last
     `Transport::poll` there was no `self.dialer`, that waker is empty.

Result: The message is stuck in the `DialerState::pending_dials`. The message is
never send to the endpoint driver. The dial never succeeds.

This commit includes a hot-fix. It demonstrates the above issue more than it
represents a solid fix.
@elenaf9 elenaf9 marked this pull request as ready for review January 17, 2023 16:02
transports/quic/src/transport.rs Outdated Show resolved Hide resolved
transports/quic/tests/smoke.rs Show resolved Hide resolved
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Change looks good to me, minus the small suggestion below.

Thanks for putting more thought into this @elenaf9!

transports/quic/src/transport.rs Outdated Show resolved Hide resolved
@mxinden
Copy link
Member

mxinden commented Jan 18, 2023

Also can you add a short changelog entry? I forgot to add one in #3306 unfortunately.

@mergify
Copy link
Contributor

mergify bot commented Jan 23, 2023

This pull request has merge conflicts. Could you please resolve them @elenaf9? 🙏

@mergify mergify bot merged commit dcfa7ec into libp2p:master Jan 23, 2023
@elenaf9 elenaf9 deleted the quic/dialer-wakeup branch January 27, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants