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

async_std support #502

Closed
Demi-Marie opened this issue Nov 18, 2019 · 18 comments · Fixed by #1364
Closed

async_std support #502

Demi-Marie opened this issue Nov 18, 2019 · 18 comments · Fixed by #1364
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Demi-Marie
Copy link
Contributor

quinn-proto is extremely low-level and difficult to use. quinn is much nicer to use, but depends on Tokio. Would it be possible for quinn to also support async_std via a Cargo feature?

@Ralith Ralith added enhancement New feature or request good first issue Good for newcomers labels Nov 18, 2019
@Ralith
Copy link
Collaborator

Ralith commented Nov 18, 2019

Thanks for the issue! I think the right way to approach this is to make quinn abstract over runtime, i.e. the thing providing wake-ups for I/O and timers, as cargo features can't be mutually exclusive. This might also be useful for more pure end-to-end testing. Note that quinn implements its own UdpSocket to gain access to low-level features like explicit congestion notification flags, and a good solution should avoid duplicating that code.

@Demi-Marie
Copy link
Contributor Author

Due to async-rs/async-std#293 quinn’s UdpSocket won’t be usable on async-std, so we will need to provide an alternative. That should be doable, however.

@jean-airoldie
Copy link
Contributor

From what i understand you could replace the tokio dependency with smol & futures-io:

  • tokio::io::Async{Read,Write} becomes futures_io::Async{Read,Write}
  • tokio-rustls becomes async-tls
  • PollEventedmio::net::UdpSocket becomes smol::Asyncstd::net::UdpSocket
  • tokio::time becomes either futures-timer or smol::Timer

However you would need to find a non tokio alternative for tokio_util::codec, although it wouldn't be too hard to adapt the code.

I think this should make quinn abstract over runtime.

@Ralith
Copy link
Collaborator

Ralith commented Jul 29, 2020

From what i understand you could replace the tokio dependency with smol & futures-io:

My understanding is that this amounts to a hidden hard dep on a smol background thread, so we'd just be trading one required runtime for another. Unless I misunderstand how smol works these days? I'd prefer to be genuinely runtime-agnostic as outlined above.

tokio::io::Async{Read,Write} becomes futures_io::Async{Read,Write}

quinn implements both of these traits for streams already; the tokio variants could be feature flagged easily enough.

However you would need to find a non tokio alternative for tokio_util::codec, although it wouldn't be too hard to adapt the code.

Indeed that's pretty trivial code, which we could easily vendor if need be.

@jean-airoldie
Copy link
Contributor

Unless I misunderstand how smol works these days? I'd prefer to be genuinely runtime-agnostic as outlined above.

Right. The only real benefit is that you can run your quinn sockets in a non-tokio runtime without crashing.

@Ralith
Copy link
Collaborator

Ralith commented Jul 29, 2020

You can spawn a thread to run tokio in the background too (you just have to wrap the initial setup in Handle::enter), so I don't think that would buy us anything.

@Ralith
Copy link
Collaborator

Ralith commented Jul 29, 2020

Thanks for your interest, regardless! Hopefully this type of composability problem gets easier to address in the future.

@yvonmanzi
Copy link

yvonmanzi commented Mar 24, 2021

Hi, @Ralith! I would like to bring up this issue once again. Any progress in this direction? We would like to use quinn in our project, which relies heavily on async-std, so any effort to make quinn runtime agnostic would be amazing. Do you have any new insights into how we can make that happen? I am happy to help with the effort but I'd definitely need help figuring out how to go about solving this.

@djc
Copy link
Member

djc commented Mar 24, 2021

@yvonmanzi so far no progress has been made on this issue (that I am aware of). We'll mentor you through implementing if that's of interest to you, or otherwise I can provide commercial support if that's an option.

@yvonmanzi
Copy link

Thank you @djc for a quick response. I definitely appreciate the mentorship. I am going to start looking into various routes through which I can approach this. Any pointers, advice, etc for me to look into before I get started would go a long way.

@djc
Copy link
Member

djc commented Mar 24, 2021

You could maybe look at the trust-dns crate for some examples. It has a Runtime trait that already abstracts over some of the things we would also need. Would probably useful to start with enumerating a list of tokio types and functions used and post them back here so we can review what to do for each. The hardest part is probably the custom UdpSocket, you may want to start with that.

@yvonmanzi
Copy link

Okay, thanks!

@aryan9600
Copy link

Hello @Ralith @djc we want to add QUIC support to tremor which uses async_std as an async runtime. Abstracting the runtime sounds perfect as it gives us the option of not having to use smol to interop between tokio and async_std. Is there any progress on this? I am willing to work on this (given of course, no one else is already) although I will definitely need some mentorship.

@djc
Copy link
Member

djc commented Jun 9, 2021

@aryan9600 I'm not aware of any progress so far. Would be great if you can work on this, will be happy to guide you along.

@jean-airoldie
Copy link
Contributor

Hello @Ralith @djc we want to add QUIC support to tremor which uses async_std as an async runtime. Abstracting the runtime sounds perfect as it gives us the option of not having to use smol to interop between tokio and async_std. Is there any progress on this? I am willing to work on this (given of course, no one else is already) although I will definitely need some mentorship.

You don't actually need to use smol to interrop. All you need is to lazy initialize a tokio::runtime::Handle and then call tokio::runtime::Handle::enter before each quinn call to tokio.

@yu-re-ka
Copy link

I have the quinn server example running with async-std, if there is still interest I could implement async-std and tokio support using two seperate feature flags.

@parazyd
Copy link

parazyd commented May 4, 2022

I have the quinn server example running with async-std, if there is still interest I could implement async-std and tokio support using two seperate feature flags.

This would be lovely. I can help too if needed.

@Ralith
Copy link
Collaborator

Ralith commented Jun 3, 2022

Fix drafted in #1364. Review from people familiar with async-std would be particularly welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants