-
Notifications
You must be signed in to change notification settings - Fork 247
chore: upgrade reqwest from v0.11 to v0.12 #7646
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
base: development
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @leet4tari, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a critical infrastructure update, bringing the HTTP client ( Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request upgrades reqwest from v0.11 to v0.12 and hyper from v0.14 to v1.0 to address RUSTSEC-2025-0134. The changes correctly adapt the codebase to the new APIs of these libraries. My review focuses on ensuring the migration is complete and correct. I've identified a regression in the server's shutdown behavior and a couple of minor improvements in error handling.
| loop { | ||
| let (tcp, _) = listener.accept().await?; | ||
| let svc = randomx_service.clone(); | ||
| let io = hyper_util::rt::TokioIo::new(tcp); | ||
|
|
||
| tokio::task::spawn(async move { | ||
| if let Err(e) = http1::Builder::new() | ||
| .serve_connection(io, &*svc) | ||
| .await | ||
| { | ||
| error!("Connection error: {}", e); | ||
| } | ||
| }); | ||
| } |
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.
The new server implementation uses an infinite loop which will never terminate gracefully. The previous hyper::Server implementation supported graceful shutdown. This is a regression in behavior, as the server can now only be stopped by killing the process.
A graceful shutdown mechanism should be added, for example by listening for a Ctrl+C signal. This would also allow the start_merge_miner function to terminate cleanly, which it currently does not.
let mut shutdown = Box::pin(tokio::signal::ctrl_c());
loop {
tokio::select! {
biased;
_ = &mut shutdown => {
info!(target: LOG_TARGET, "Shutdown signal received, terminating server.");
break;
}
res = listener.accept() => {
let (tcp, _) = res?;
let svc = randomx_service.clone();
let io = hyper_util::rt::TokioIo::new(tcp);
tokio::task::spawn(async move {
if let Err(e) = http1::Builder::new()
.serve_connection(io, &*svc)
.await
{
error!("Connection error: {}", e);
}
});
}
}
}
return Ok(());| Ok(bytes) | ||
| pub async fn read_body_until_end<B: HttpBodyTrait + Unpin>(body: B) -> Result<BytesMut, MmProxyError> { | ||
| let collected = body.collect().await | ||
| .map_err(|_e| MmProxyError::InvalidMonerodResponse("Failed to read body".to_string()))?; |
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.
The error from body.collect().await is being ignored. While collect() on a body is not expected to fail often, it's better to include the actual error in the log message for easier debugging if it does happen.
| .map_err(|_e| MmProxyError::InvalidMonerodResponse("Failed to read body".to_string()))?; | |
| .map_err(|e| MmProxyError::InvalidMonerodResponse(format!("Failed to read body: {}", e)))?; |
| } | ||
| fn json_response_to_boxbody(resp: Response<serde_json::Value>) -> Response<ProxyBody> { | ||
| let (parts, body) = resp.into_parts(); | ||
| let body_bytes = serde_json::to_vec(&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.
serde_json::to_vec(&body) on a serde_json::Value should not fail. However, using unwrap_or_default() will silently produce an empty response body if it ever does, which can make debugging difficult. Using expect() with a descriptive message is safer, as it would cause a panic and make any unexpected problem immediately obvious.
| let body_bytes = serde_json::to_vec(&body).unwrap_or_default(); | |
| let body_bytes = serde_json::to_vec(&body).expect("json::Value should always be serializable"); |
sdbondi
left a comment
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.
utACK
| } | ||
|
|
||
| async fn serve(listener: TcpListener, service: MergeMiningProxyService) -> Result<(), MmProxyError> { | ||
| loop { |
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.
we need to add a shutdown here, you can use TariShutdown if you want, but this is an endless loop here
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.
Shutdown here isn't necessary; the calling code will stop polling the future returned from serve on interrupt/shutdown/ctrl+c and will drop it at the end of the function.
let mut shutdown = Box::pin(tokio::signal::ctrl_c());
let mut serve_fut = Box::pin(serve(listener, randomx_service));
tokio::select! {
_ = &mut shutdown => {
info!(target: LOG_TARGET, "Ctrl-C received, shutting down merge mining proxy...");
println!("Ctrl-C: shutting down merge mining proxy...");
}
result = &mut serve_fut => {
if let Err(e) = result {
error!(target: LOG_TARGET, "Error in merge mining proxy service: {}", e);
}
}
}
Ok(())
},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.
100% correct
But if someone else calls this function without calling it from some tokio loop with a select, its a going to end up in an endless loop.
I would rather we combine to two have an loop with the tokio select loop awaiting listener.accept() and the shutdown.
The way async fn serve( is written is assumed its called from a service that will drop it somehow, but you would never know that just by looking at the rust function header or place from where its called.
Description
upgrade
reqwestfrom v0.11 to v0.12upgrade
hyperfrom v0.14 to v1.6.0 - need for changes inreqwestv0.12Motivation and Context
Avoid RUSTSEC-2025-0134 and assist with tari-project/tari-ootle#1672
How Has This Been Tested?
Builds all binaries in locally and in fork
What process can a PR reviewer use to test or verify this change?
Check the audit report that reqwest is now v0.12 or above
Breaking Changes