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

Add shutdown grace period #390

Merged
merged 1 commit into from
Nov 12, 2021
Merged

Add shutdown grace period #390

merged 1 commit into from
Nov 12, 2021

Conversation

hannesdejager
Copy link
Collaborator

@hannesdejager hannesdejager commented Nov 12, 2021

Improvement for #386

When doing a graceful shutdown you don't want things to take to long, so a grace period can be specified.

Logs for shutdown within grace period:

 Nov 12 16:07:19.160 INFO Shutting down FTP server
 Nov 12 16:07:19.160 INFO HTTP shutdown OK
lib: libunftp
 Nov 12 16:07:19.160 DEBG Shutting down within 10s
 Nov 12 16:07:19.161 DEBG Graceful shutdown complete
module: main

and the not so happy case:

 Nov 12 16:27:35.985 INFO HTTP shutdown OK
lib: libunftp
 Nov 12 16:27:35.985 DEBG Shutting down within 10s
 trace-id: 0x45bb0af218d17c28
  source: 127.0.0.1:57427
   Nov 12 16:27:35.985 INFO Shutting down control loop
 Nov 12 16:27:45.987 WARN Could not finish shutdown normally within grace period
module: main
 Nov 12 16:27:45.988 ERRO FTP server error: ServerError { msg: "shutdown error", source: ShutdownError { msg: "shutdown grace period expired" } }
 Nov 12 16:27:45.988 INFO FTP exiting

@@ -177,7 +178,7 @@ impl Default for SiteMd5 {

/// The options for [Server.shutdown_indicator](crate::Server::shutdown_indicator) that allows users
/// to specify the way in which a (graceful) shutdown of libunftp should happen.
pub enum Shutdown<Signal: Future<Output = ()> + Send + Sync> {
pub enum Shutdown<Signal: Future<Output = Duration> + Send + Sync> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not really happy with the interface here, I may change it still.

current usage:

    let mut server = Server::with_authenticator(storage_backend, Arc::new(authenticator))
        .greeting("Welcome to unFTP")
        .passive_ports(start_port..end_port)
        .idle_session_timeout(idle_timeout)
        .logger(root_log.new(o!("lib" => "libunftp")))
        .passive_host(passive_host)
        .sitemd5(md5_setting)
        .shutdown_indicator(options::Shutdown::GracefulAcceptingConnections( async move {
            shutdown.recv().await.ok();
            info!(l, "Shutting down FTP server");
            Duration::from_secs(10)
        }))
        .metrics();

@hannesdejager hannesdejager merged commit 0ff97e5 into master Nov 12, 2021
@hannesdejager hannesdejager deleted the hannes/graceful branch November 12, 2021 15:32
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.

1 participant