-
Notifications
You must be signed in to change notification settings - Fork 257
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
Prepare for Hyper 1.0.0 Upgrade: Enable Deprecated Features and Resolve Deprecations #1938
base: main
Are you sure you want to change the base?
Conversation
- Enabled the `deprecated` and `backports` feature flag in Hyper 0.14 to resolve deprecation warnings. - Temporarily addresses warning issues with older `to_bytes` api. - Ensures the codebase remains functional while preparing for a full upgrade to Hyper 1.0.0. This change allows us to address deprecation warnings without immediately migrating to the newer Hyper 1.0.0 APIs. A full upgrade will be planned in subsequent commits.
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.
PR Summary
Let me provide a concise summary of the key changes in this PR:
- Replaces deprecated
hyper::body::to_bytes()
withhyper::body::HttpBody::collect().await.unwrap().to_bytes()
across multiple files to prepare for Hyper 1.0.0 upgrade - Enables 'backports' and 'deprecated' features in Hyper 0.14.23 dependency to maintain compatibility during transition
- Introduces potential unwrap() issues in some error handling paths that should be reviewed
- Changes are primarily in test code and HTTP body handling, maintaining existing functionality while using newer API patterns
Here are the 3 most important points to focus on:
-
The use of
unwrap()
aftercollect()
in several files likeprovisioner_server.rs
could lead to panics if body collection fails - consider using proper error handling instead. -
The PR enables deprecated features as a temporary solution, but a follow-up PR will be needed for the full Hyper 1.0.0 migration as noted in issue [Improvement]: Bump shuttle-tower service to hyper 1.1.0 #1517.
-
The changes are focused on HTTP body handling patterns and don't modify core business logic, making this a relatively safe preparation step for the larger upgrade.
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
15 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings | Greptile
let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); | ||
let body = hyper::body::HttpBody::collect(response.into_body()) | ||
.await | ||
.unwrap() |
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.
style: consider handling the unwrap() case more gracefully since this is a test that could fail
let public_key = hyper::body::HttpBody::collect(response.into_body()) | ||
.await | ||
.unwrap() | ||
.to_bytes(); |
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.
style: consider extracting body collection logic into a helper method to avoid repetition
let body = hyper::body::HttpBody::collect(response.into_body()) | ||
.await | ||
.unwrap() | ||
.to_bytes(); |
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.
style: This pattern is repeated throughout the file. Consider extracting this common body collection logic into a helper function to reduce duplication and make future API changes easier.
# not great, but waiting for WebSocket changes to be merged | ||
hyper-reverse-proxy = { git = "https://github.com/chesedo/hyper-reverse-proxy", branch = "bug/host_header" } |
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.
style: Using a git dependency for hyper-reverse-proxy could cause build instability. Consider pinning to a specific commit hash rather than branch, or better yet, wait for the WebSocket changes to be merged and use a released version.
let body = hyper::body::HttpBody::collect(response.into_body()) | ||
.await | ||
.unwrap() | ||
.to_bytes(); |
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.
style: consider extracting this repeated body collection pattern into a helper function to reduce duplication
let convert: Value = serde_json::from_slice(&body) | ||
.expect("failed to deserialize body as JSON, did you login?"); |
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.
style: The error message 'did you login?' may be misleading since this could fail for other reasons like invalid JSON. Consider a more generic error message.
let body = hyper::body::HttpBody::collect(res.body_mut()) | ||
.await | ||
.unwrap() | ||
.to_bytes(); |
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.
style: Consider handling unwrap() here with proper error propagation since this is in the request path
let body = match hyper::body::HttpBody::collect(token_response.into_body()) | ||
.await | ||
{ | ||
Ok(aggregated_body) => aggregated_body.to_bytes(), | ||
Err(err) => { |
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.
style: The new collect().await?.to_bytes()
pattern could potentially use more memory than the previous to_bytes()
since it aggregates the entire body before converting to bytes. Consider adding a size limit check.
.unwrap_or_default(); | ||
.unwrap_or_default() | ||
.to_bytes(); | ||
|
||
let convert: serde_json::Value = serde_json::from_slice(&body).unwrap_or_default(); |
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.
style: Consider adding error handling for JSON parsing failures rather than using unwrap_or_default
let body = hyper::body::HttpBody::collect(resp.into_body()) | ||
.await? | ||
.to_bytes(); |
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.
style: Consider handling potential memory issues by adding a size limit to body collection
Hello @djnovin, thanks for the PR! This looks great, and it seems like you've gone about starting the upgrade in a reasonable and correct way. While we do want to upgrade hyper and associated crates, a lot of the services in this repository are about to be deprecated at the end of January (e.g. Still, we do want to update the |
Hello again @djnovin! We've discussed this internally, and decided that we'd rather wait with this upgrade until the old version of the platform has been fully deprecated. That is planned for the end of January. There will then be some cross-cutting work between these public crates and the code in our currently private repos, so it may still be a bit tricky for an external contributor to work. However, if we do think it's suitable for you to work on, we'll let you know in case you're still interested at the time. And again, thank you for the contribution, it looks great, and had it not been for the ongoing platform switch, we would have been able to merge it quickly. We aim to open more issues for contributors once the new version of the platform is more settled, so we hope to see you again then! |
This change allows us to address deprecation warnings without immediately migrating to the newer Hyper 1.0.0 APIs. A full upgrade will be planned in subsequent PRs.
Description of change
This PR prepares the codebase for upgrading Hyper from version 0.14 to 1.0.0 by addressing deprecation warnings and enabling compatibility with newer APIs. Key changes include:
Enabled the deprecated feature flag in Hyper 0.14 to resolve immediate deprecation warnings.
Refactored usages of deprecated APIs (e.g., aggregate and to_bytes) to align with Hyper's updated patterns.
Ensured tests and functionality remain intact with the current version while paving the way for the full migration to Hyper 1.0.0.
These changes ensure that the upgrade process is smoother and minimize risks of breaking changes in subsequent steps.
#1517
How has this been tested? (if applicable)
cargo test
has been run...