-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 hyper 0.12 (WIP) #1008
Conversation
Seeing this open I realize I should have shared my progress sooner. I have an async fork of Rocket that supports async routes, |
@jebrosen, I didn't know that you are working on an update as well. BTW, it sounds very nice what you are doing. Do you think we should continue this PR and should use your insights to finish this update? This PR has some issue in it and Rocket could benefit from your and others point of view. Based on the upgrade Rocket could start integrate async routes, etc. |
@jebrosen @schrieveslaach Can I task you with working together to create a comprehensive PR? We should do this in the open to avoid duplicating efforts in the future. Perhaps we can start by having you share your work, @jebrosen, and perhaps you can take the lead to incorporate @schrieveslaach contributions into your ongoing effort. |
I have rebased and updated the comments on my branch: https://github.com/SergioBenitez/Rocket/compare/master...jebrosen:async?expand=1. I have been working on it on and off for several months now, but churn around Here's what I was thinking, roughly in order:
... and more after that. I have more notes and ideas of things that need to be done, but I have to leave it at this for right now. |
@SergioBenitez, sure. 😃 @jebrosen, thanks for your comments. How do you propose to continue? Should I wait for your comments and than I should start to adopt this PR? |
If you have the time and interest, I would appreciate if you could take a look at my work and share your opinions on anything we both did but in different ways. I'll do the same, but that might be a few days away still and this would help me know what to watch out for. I will want to be careful about merging our code together, maybe in an "async" branch in this repository. You deserve credit for starting this, and I also want to keep the other work I've done. |
Okay, I will have a look at your work.
Thanks for your appreciation. I agree with you that we should incorporate our development branches. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing this took less time than I thought; the large deletions and simple renames and TODOs inflated the numbers and tricked me into thinking it would take longer.
Overall, I think there are only a few things here that I haven't also done -- keeping From<Mime> for ContentType
is one example and probably a good idea. I also like From<Response> for hyper::Response
.
I think what I would like to do is 1) get Rocket master on 2018, 2) adopt your commit for most/all of the changes in http
and some of the changes in rocket.rs
, and 3) layer my work on top, and make that the async
branch. Then we can re-assess what work remains to be done.
@@ -281,11 +281,11 @@ impl From<Mime> for ContentType { | |||
#[inline] | |||
fn from(mime: Mime) -> ContentType { | |||
// soooo inefficient. | |||
let params = mime.2.into_iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had dropped mime
support entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From your comment above, I think you want to keep mime
support, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if there's no downside, at least. I think it would just add non-async-related churn to an async development branch for now.
core/http/Cargo.toml
Outdated
@@ -21,7 +21,9 @@ private-cookies = ["cookie/secure"] | |||
[dependencies] | |||
smallvec = "0.6" | |||
percent-encoding = "1" | |||
hyper = { version = "0.10.13", default-features = false } | |||
hyper = { version = "0.12.28", default-features = false, features = ["runtime"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to use tokio
manually instead of via the runtime
feature (for easier TLS handling, I think).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I can change this as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to change it in your branch, or not - I foresee a big project of a merge one of the coming weekends either way!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jebrosen One thing to keep in mind is that people will definitely want to run stuff other than Rocket on the Tokio event loop (e.g. async database calls using tokio-postgres). So either:
- Rocket should (optionally) accept a tokio reactor to run on
- Rocket should be able to expose it's own reactor for use by other code
- The tokio runtime should be used (I think this allows for this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC hyper 0.12 actually requires tokio runtime specifically (hyper 0.13 might not.) I definitely like the idea of allowing a user-configured runtime, though.
core/lib/src/rocket.rs
Outdated
fairings: Arc<Fairings>, | ||
} | ||
|
||
impl<Ctx> hyper::MakeService<Ctx> for Rocket { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the key structural differences between our approaches - I used hyper::service_fn
as in jebrosen@27a59ef#diff-a9ea99dbf2f3bc38a7d7e4c36a99a288R786. Do you have an opinion on which is better? I prefer hyper::service_fn
because it's far shorter, but is there a benefit to explicitly specifying the associated types by implementing MakeService
manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some struggle with hyper::service_fn
and the idea of using the MakeService
trait had seemed to me very handy and more robust against future changes in hyper. But that's only a gut feeling. Nevertheless, I think we have to use some kind of cloning of Arc<SomeRocketStruct>
here. I use it in RocketHyperService
, you use it in hyper::service_fn
.
really looking forward when this MR will be ready :) |
I probably wouldn't be of much help in porting the code to 0.12, but I can certainly take a look over code before merging if wanted. |
Rocket is now on Rust 2018! Looking forward to seeing progress here. @jebrosen What are the next steps? |
@schrieveslaach, do you have any changes you made since this PR was opened? The next step on my list is to rebase this PR on top of master, then my changes on top of that. That should give us master -> partial hyper 0.12 upgrade -> full async/await in core and codegen. Since it's a massive and incomplete breaking change that breaks tests left and right, I had the idea to start an Ideally we would have a way to divvy up tasks so there's not too much duplication of work and interested parties could pitch in -- @SergioBenitez do you have any opinions here as far as a tracking issue(s) or PR submission/review? |
@jebrosen, @SergioBenitez, I'll have time on sunday and I'll work on it again. I keep you posted. |
- Use hyper's MakeService implementation with futures API - Use tokio runtime to serve HTTP backend
@jebrosen, @SergioBenitez, I rebased my fork with the current master and I improved my code a bit. For example, I restored some code that I had to disable. I also switched to tokio runtime. I used the code @jebrosen's fork. This PR still uses |
I will start working on merging these together now. I will likely make a few changes - e.g. using a single |
@jebrosen, I'm looking forward to get this done. Just out of curiosity: do you create an async branch and do you accept this PR by merging it into the async branch? |
Just asking out of curiosity: why did you both end up choosing tokio instead of trying something else (e.g. Runtime)? Perhaps was the async story already started at that time and you just restarted from there? Me too, I'm trying to figure out the "right" library to use and I find tokio pretty hard to use (disclaimer: not an experienced Rustacean). Anyways, thank you so much for pushing this forward, I'm really looking forward to it 👍 |
In any case, the choice will be more or less invisible to Rocket users. |
awesome @lnicola thanks for explaining! As long as the async story is ergonomic to use for "the rest of us", I'm super happy with whatever choice ;-) |
@schrieveslaach My I originally went with |
Update: I got busy with a few other things, bit I plan to come back to this very soon. Thank you everyone for your patience. My |
I've merged this and my code as the |
In order to support websockets, it is necessary to upgrade to the newest hyper version (see this comment in #90). This PR is a simple proof of concept to upgrade to hyper 0.12 which was a bit difficult and I hope, that we can use this PR as a WIP PR to upgrade to hyper 0.12.
I hope that you can support me to finish the upgrade.