Skip to content

feat: remove async_std support in TCP crate #5955

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

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

Conversation

gitToki
Copy link
Contributor

@gitToki gitToki commented Mar 25, 2025

ref #5935

crate to update:
swarm, mDNS, and the transports TCP, QUIC and DNS.

@dariusc93 dariusc93 changed the title chore!: deprecate async_std support in TCP crate chore: deprecate async_std support in TCP crate Mar 25, 2025
Copy link
Member

@dariusc93 dariusc93 left a comment

Choose a reason for hiding this comment

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

Thanks. Left a couple of comments

async-io = ["dep:async-io", "if-watch/smol"]
default = ["tokio"]
Copy link
Member

Choose a reason for hiding this comment

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

We probably should not have it default to tokio right now since it would require disabling default features to enable the needed feature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will correct next commit

Comment on lines 29 to 31
//! This crate provides a [`async_io::Transport`] (deprecated) and [`tokio::Transport`],
//! which implement the [`libp2p_core::Transport`] trait for use as a
//! transport with `libp2p-core` or `libp2p-swarm`.
Copy link
Member

Choose a reason for hiding this comment

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

Though the comment is modified, it is also duplicated from above.

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Can we not soft deprecate and just hard deprecate? CC @elenaf9 @dariusc93

@elenaf9
Copy link
Member

elenaf9 commented Mar 26, 2025

Can we not soft deprecate and just hard deprecate? CC @elenaf9 @dariusc93

@gitToki initially did that, but I asked for a soft deprecation. I think a soft deprecation makes sense here because we might still have users that use async_std. It would a) give them time to object before we do a hard removal and b) offer a transition period for them.

Any specific reason why you'd prefer a direct removal @jxs?

@dariusc93
Copy link
Member

Can we not soft deprecate and just hard deprecate? CC @elenaf9 @dariusc93

Would there be any reason to suddenly do a hard deprecation vs soft? Imo, I think we should do a soft (though I am not against a hard one) to give users a time to switch or figure out plans on migration (or supporting the executor themselves for the respected protocols and utils).

@jxs
Copy link
Member

jxs commented Apr 3, 2025

Hi!

Any specific reason why you'd prefer a direct removal @jxs?

the reason is more work, double the PR's for something that has been declared as unmaintained, I feel redundant to have a version for users to remove their usage when they probably are already removing, added to the fact that I have seen soft deprecations lost in time.
But if you two agree that we should do soft I cede :)

@gitToki
Copy link
Contributor Author

gitToki commented Apr 13, 2025

updated, should be good. @dariusc93 please let me know if everything look good to you

@@ -47,8 +47,6 @@ use libp2p_core::{
multiaddr::{Multiaddr, Protocol},
transport::{DialOpts, ListenerId, PortUse, TransportError, TransportEvent},
};
#[cfg(feature = "async-io")]
pub use provider::async_io;
#[cfg(feature = "tokio")]
pub use provider::tokio;
use provider::{Incoming, Provider};
Copy link
Member

Choose a reason for hiding this comment

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

@jxs @dariusc93 based on the discussion in #5935 (comment), should we make the Incoming and Provider traits public to allow a downstream implementation?

In the other affected crates (libp2p-quic, libp2p-dns, etc.) the Provider traits are already public.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, we aren't really consistent on this. In libp2p-mdns for example the Provider trait is also private.

Still, I think we should make them public in all crates.

Copy link
Member

Choose a reason for hiding this comment

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

yeah makes sense to me, and possibly isolate them so they aren't duplicated right?

Copy link
Member

Choose a reason for hiding this comment

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

yeah makes sense to me, and possibly isolate them so they aren't duplicated right?

Yes good idea. But let's do that in a follow-up PR.

@jxs jxs changed the title chore: deprecate async_std support in TCP crate feat: deprecate async_std support in TCP crate Jun 4, 2025
Copy link
Contributor

mergify bot commented Jun 4, 2025

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

@elenaf9 elenaf9 changed the title feat: deprecate async_std support in TCP crate feat: remove async_std support in TCP crate Jun 4, 2025
@gitToki
Copy link
Contributor Author

gitToki commented Jun 5, 2025

Is it good to you now @elenaf9 ? 🫡

Copy link
Member

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

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

Thank you for the follow-up @gitToki

Comment on lines 205 to 211

use crate::{cbor::codec::Codec, Codec as _};

#[async_std::test]
#[tokio::test]
async fn test_codec() {
let expected_request = TestRequest {
payload: "test_payload".to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

Changing the request-response tests to use tokio is out of scope for this PR but blocked by it. There is a pending PR #5857 for this, that is blocked by failing tests. Would be interested in helping on that PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sure I will try to take a look

Comment on lines 316 to 330
#[tokio::test]
async fn dialer_connects_to_listener_ipv4() {
let a = "/ip4/127.0.0.1/tcp/0/ws".parse().unwrap();
futures::executor::block_on(connect(a))
connect(a).await
}

#[test]
fn dialer_connects_to_listener_ipv6() {
#[tokio::test]
async fn dialer_connects_to_listener_ipv6() {
let a = "/ip6/::1/tcp/0/ws".parse().unwrap();
futures::executor::block_on(connect(a))
connect(a).await
}

fn new_ws_config() -> Config<tcp::async_io::Transport> {
Config::new(tcp::async_io::Transport::new(tcp::Config::default()))
fn new_ws_config() -> Config<tcp::tokio::Transport> {
Config::new(tcp::tokio::Transport::new(tcp::Config::default()))
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here. This should be a separate PR, and the current PR should only be merged afterwards.

Copy link
Contributor Author

@gitToki gitToki Jun 7, 2025

Choose a reason for hiding this comment

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

Are you OK if I open a new PR for websocket ? I already made the change in a new branch (it was fast), available here: master...gitToki:rust-libp2p:websocket

Copy link
Member

Choose a reason for hiding this comment

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

Sure, thanks!

Copy link
Contributor

mergify bot commented Jun 9, 2025

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

mergify bot pushed a commit that referenced this pull request Jun 10, 2025
migrate from async-std to tokio, asked before [here](#5955 (comment))

Pull-Request: #6054.
@gitToki
Copy link
Contributor Author

gitToki commented Jun 10, 2025

dcutr and mplex fail but only the test have been updated so no version bump. It should be good now

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Thanks for the patience Toki, left comments

@@ -149,22 +149,6 @@ impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, Quic
.with_behaviour(constructor)
}
}
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std", feature = "dns"))]
Copy link
Member

Choose a reason for hiding this comment

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

this should also be in the dns deprecation PR right?

@@ -181,21 +165,6 @@ impl<T: AuthenticatedMultiplexedTransport> SwarmBuilder<super::provider::Tokio,
.with_dns()
}
}
#[cfg(all(not(target_arch = "wasm32"), feature = "async-std", feature = "dns"))]
Copy link
Member

Choose a reason for hiding this comment

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

same as above, shouldn't this be in the dns PR?

@@ -114,6 +113,7 @@ impl<Provider> SwarmBuilder<Provider, TcpPhase> {
}
}

// Shortcuts
Copy link
Member

Choose a reason for hiding this comment

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

is this comment necessary?

@@ -1,4 +1,4 @@
## 0.13.0
## 0.13.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## 0.13.0
## 0.13.0

Comment on lines +3 to +5
- Use `tokio` for test as `async-std` support has been removed.
See [PR 5955](https://github.com/libp2p/rust-libp2p/pull/5955).

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is required right? We're only updating the tests

@@ -3,6 +3,9 @@
- Default to `tokio` runtime.
See [PR 6024](https://github.com/libp2p/rust-libp2p/pull/6024).

- Removed `async-std` support from TCP transport.
Copy link
Member

Choose a reason for hiding this comment

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

this needs to account that new_ephemeral now defaults to using tokio, and that new_ephemeral_tokio is removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want me to open a new PR for this ? since a lot of code currently use new_ephemeral_tokio from swarm-test, or is it okay to do it in that PR since all of these changes are related to test ?

Copy link
Member

@elenaf9 elenaf9 Jun 12, 2025

Choose a reason for hiding this comment

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

this needs to account that new_ephemeral now defaults to using tokio, and that new_ephemeral_tokio is removed

new_ephemeral is still using async-std. For tokio you must use new_ephemeral_tokio. It's just that the swarm-test crate now per default enables it's tokio feature (and thus per default only exposes new_ephemeral_tokio and not new_ephemeral).

Eventually we could remove the old new_ephemeral and instead make it an alias of new_ephemeral_tokio, but I think that's a separate discussion and out of scope for this PR.

Copy link
Member

Choose a reason for hiding this comment

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

yup thanks for elaborating Elena, on this PR swarm-test should just default to tokio and we'll do the switch on another on PR

@@ -235,7 +235,7 @@ where
let peer_id = PeerId::from(identity.public());

let transport = MemoryTransport::default()
.or_transport(libp2p_tcp::async_io::Transport::default())
.or_transport(libp2p_tcp::tokio::Transport::default())
Copy link
Member

Choose a reason for hiding this comment

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

this function, new_ephemeral is still feature gated to async-std and we probably should remove new_ephemeral_tokio as new_ephemeral by default uses tokio

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

yeah thanks Elena, but then this should still use async_io then right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants