Open
Conversation
feat(configure/server): add graceful shutdown to server struct
Reason: Configuration option was previously named "grace_shutdown" this was updated to "grace_shutdown_secs" for clarity. Originally all settings files were not updated, this has now been corrected to align with the configuration struct in `src/configure/server.rs`
robatipoor
requested changes
Mar 6, 2025
Owner
robatipoor
left a comment
There was a problem hiding this comment.
Thank you for the pull request! Please get the latest update from the main branch first.
| pub struct ServerConfig { | ||
| pub addr: String, | ||
| pub port: u16, | ||
| pub grace_shutdown_secs: i64, |
Owner
There was a problem hiding this comment.
Please change the data type to std::time::Duration:
#[serde(deserialize_with = "deserialize_duration")]
pub grace_shutdown_secs: Duration,
| axum::serve(self.tcp, router).await?; | ||
| let shutdown = self.grace_shutdown_time(); | ||
| let router = create_router_app(self.state) | ||
| .layer(TraceLayer::new_for_http()) // Visibility of the request and response, change as needed. |
Owner
There was a problem hiding this comment.
Please move the two layers to the create_router_app function.
| pub async fn run(self) -> AppResult<()> { | ||
| let router = create_router_app(self.state); | ||
| axum::serve(self.tcp, router).await?; | ||
| let shutdown = self.grace_shutdown_time(); |
Owner
There was a problem hiding this comment.
I think you can remove this and directly pass the timeout to the layer.
| Ok(()) | ||
| } | ||
|
|
||
| fn grace_shutdown_time(&self) -> std::time::Duration { |
| .send(e) | ||
| .await | ||
| .unwrap_or_else(|_| unreachable!("This channel never closed.")); | ||
| let _ = sender.send(e).await; |
Owner
There was a problem hiding this comment.
I think this change does not explain why to ignore the result, but the previous code does. It might be better to add a comment : "This channel never closed."
| } | ||
|
|
||
| // Explicitly drop the sender to close the channel. | ||
| drop(sender); |
Owner
There was a problem hiding this comment.
Good point! Please change the comment to: "Drop the original unused sender."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementes graceful shutdown - closes #20