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

Upgrade to Tokio 1.0 #753

Merged
merged 36 commits into from Jan 15, 2021
Merged

Conversation

aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Nov 29, 2020

Similar to @Urhengulas' PR #741, although more complete, this PR aims to upgrade to Tokio v1.0.

I can successfully run all tests with all features enabled: cargo test --all-features.

This is my first time trying to contribute to warp, and I'm not super familiar with the internals, so please consider it a best effort :)

Fixes #725.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1 aknuds1 mentioned this pull request Nov 29, 2020
3 tasks
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Copy link

@Urhengulas Urhengulas left a comment

Choose a reason for hiding this comment

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

Good job! Only two remarks :D

Cargo.toml Outdated Show resolved Hide resolved
src/filters/fs.rs Outdated Show resolved Hide resolved
src/filters/ws.rs Outdated Show resolved Hide resolved
…tokio

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@Urhengulas Urhengulas mentioned this pull request Dec 9, 2020
5 tasks
Cargo.toml Outdated Show resolved Hide resolved
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@jhpratt
Copy link

jhpratt commented Dec 24, 2020

Tokio 1.0 has been released, so this PR should probably be updated to depend on that.

@aknuds1
Copy link
Contributor Author

aknuds1 commented Dec 24, 2020

I'm trying to upgrade to Tokio 1.0.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1
Copy link
Contributor Author

aknuds1 commented Dec 24, 2020

The remaining issue is tokio-tungstenite. Trying to upgrade it to tokio 1.0, but it's easier said than done.

@aknuds1 aknuds1 changed the title Upgrade to Tokio 0.3 Upgrade to Tokio 1.0 Dec 24, 2020
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1
Copy link
Contributor Author

aknuds1 commented Dec 24, 2020

Forked tokio-tungstenite, to upgrade it to tokio 1, and depending on it, but build still fails.

@paolobarbolini
Copy link
Contributor

paolobarbolini commented Dec 24, 2020

async-compression using bytes 1.0 should come out soon Nullus157/async-compression#111 (comment)

but build still fails

  • Sleep is now !Unpin
  • bytes_mut is now chunk_mut on BytesMut
  • bytes::buf::{Buf, BufMut} -> bytes::{Buf, BufMut} (it's top-level now)

@aknuds1
Copy link
Contributor Author

aknuds1 commented Dec 24, 2020

If anyone has tips wrt. fixing the build failures, I'm all ears :)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Cargo.toml Outdated Show resolved Hide resolved
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
src/filters/body.rs Outdated Show resolved Hide resolved
aknuds1 and others added 2 commits December 24, 2020 17:42
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@@ -56,7 +58,10 @@ pub struct Compression<F> {
/// ```
pub fn gzip() -> Compression<impl Fn(CompressionProps) -> Response + Copy> {
let func = move |mut props: CompressionProps| {
let body = Body::wrap_stream(GzipEncoder::new(props.body));
let body = Body::wrap_stream(FramedRead::new(
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you prefer FramedRead over ReaderStream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jxs To be honest, I don't remember exactly, but it was probably from an example. Do you think ReaderStream is preferable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @paolobarbolini, I can't bring myself to remember where I found this solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks @paolobarbolini. @aknuds1 I asked because I was not sure either, Previously FrameReader was the way to achieve AsyncRead to Stream conversion, but since ReaderStream was introduced I would maybe suggest ReaderStream as it's simpler, and recommended for this cases on tokio-util doc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seanmonstar Do you have any opinion on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I converted from FramedRead into ReaderStream, ass @jxs recommended. I don't really know personally if there are any practical differences, but I can tell that the API is simpler (a second argument to FramedRead::new can be dropped). I trust @jxs knows more about this than I do, and I'll let @seanmonstar be the judge.

Copy link
Collaborator

@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.

LGTM thanks! 🎆

  • Test (uds, --features tokio/uds) also needs to be renamed on the repository settings
  • should the tokio_util dependent filters (fs, compression) also be featured gated?

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Copy link
Owner

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

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

Excellent work! I believe this is very close.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
.on_upgrade()
let mut resp = Response::new(self.ws.body);
if let Some(on_upgrade) = self.ws.on_upgrade {
resp.extensions_mut().insert(on_upgrade);
Copy link
Owner

Choose a reason for hiding this comment

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

If you already have the extension, you don't need to insert it here to remove it again. (on_upgrade is the same as fut).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seanmonstar I think I see what you mean, and try to simplify it to the best of my ability. Please have a look.

…tokio

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@koivunej
Copy link

koivunej commented Jan 12, 2021

Should the return type of warp::body::stream() now have a stream of Bytes instead of impl Buf in: https://github.com/aknuds1/warp/blob/bb2f511fc8785784089ebdb12861bbc32e4cef5d/src/filters/body.rs#L77-L78

This following ... Bytes change tokio-rs/bytes#439, which removed Buf::to_bytes and added Buf::copy_to_bytes. Well, I guess the buf.copy_to_bytes(buf.remaining()) should work just as well.

EDIT: found the change

@paolobarbolini
Copy link
Contributor

This following ... some Bytes change I cannot track down, which removed Buf::to_bytes.

It was replaced by Buf::copy_to_bytes @koivunej

@Kiskae
Copy link

Kiskae commented Jan 12, 2021

It appears 657f1c6 broke the build since warp::test::handshake uses hyper::Client:

   Compiling warp v0.2.5 (https://github.com/aknuds1/warp?branch=chore/upgrade-tokio#bb2f511f)
error[E0433]: failed to resolve: could not find `Client` in `hyper`
   --> /home/x/.cargo/git/checkouts/warp-2008e9c17b453427/bb2f511/src/test.rs:518:36
    |
518 |             let upgrade = ::hyper::Client::builder()
    |                                    ^^^^^^ could not find `Client` in `hyper`

error: aborting due to previous error

@aknuds1
Copy link
Contributor Author

aknuds1 commented Jan 12, 2021

It appears 657f1c6 broke the build since warp::test::handshake uses hyper::Client:

   Compiling warp v0.2.5 (https://github.com/aknuds1/warp?branch=chore/upgrade-tokio#bb2f511f)
error[E0433]: failed to resolve: could not find `Client` in `hyper`
   --> /home/x/.cargo/git/checkouts/warp-2008e9c17b453427/bb2f511/src/test.rs:518:36
    |
518 |             let upgrade = ::hyper::Client::builder()
    |                                    ^^^^^^ could not find `Client` in `hyper`

error: aborting due to previous error

@Kiskae What's the command to reproduce your failure?

@Kiskae
Copy link

Kiskae commented Jan 12, 2021

@aknuds1 Calling cargo build with the branch as a dependency seems to trigger it:

[package]
name = "repro"
version = "0.1.0"
edition = "2018"

[dependencies]
warp = {git = "https://github.com/aknuds1/warp", branch = "chore/upgrade-tokio"}

@aknuds1
Copy link
Contributor Author

aknuds1 commented Jan 12, 2021

@Kiskae Aha, I see the problem, it's because src/test.rs contains public utilities and depends on hyper::Client. Guess I'll have to reintroduce the dependency on hyper's client feature @seanmonstar.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@nickelc
Copy link
Contributor

nickelc commented Jan 12, 2021

@Kiskae Aha, I see the problem, it's because src/test.rs contains public utilities and depends on hyper::Client. Guess I'll have to reintroduce the dependency on hyper's client feature @seanmonstar.

i think another option could be to make it an optional test feature that requires hyper/client

@seanmonstar seanmonstar merged commit ffefea0 into seanmonstar:master Jan 15, 2021
@aknuds1 aknuds1 deleted the chore/upgrade-tokio branch January 15, 2021 18:00
@aknuds1
Copy link
Contributor Author

aknuds1 commented Jan 15, 2021

Thanks @seanmonstar! 🎉

jxs added a commit to jxs/warp that referenced this pull request Jun 27, 2021
Co-authored-by: janpetschexain <58227040+janpetschexain@users.noreply.github.com>
Co-authored-by: João Oliveira <hello@jxs.pt>
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
Co-authored-by: teenjuna <53595243+teenjuna@users.noreply.github.com>
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.

Upgrade to Tokio v1