Skip to content

Commit

Permalink
Refactor cleanup functions to use async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
YHM404 committed Apr 20, 2024
1 parent 58946a8 commit 3cd52fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
13 changes: 4 additions & 9 deletions pingora-core/src/apps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ pub trait ServerApp {
) -> Option<Stream>;

/// This callback will be called once after the service stops listening to its endpoints.
fn cleanup(&self) {}

/// This callback will be called once after the service stops listening to its endpoints.
///
/// Used for async cleanup tasks.
async fn async_cleanup(&self) {}
async fn cleanup(&self) {}
}

/// This trait defines the interface of an HTTP application.
Expand All @@ -82,7 +77,7 @@ pub trait HttpServerApp {
None
}

fn http_cleanup(&self) {}
async fn http_cleanup(&self) {}
}

#[cfg_attr(not(doc_async_trait), async_trait)]
Expand Down Expand Up @@ -146,7 +141,7 @@ where
}
}

fn cleanup(&self) {
self.http_cleanup()
async fn cleanup(&self) {
self.http_cleanup().await;
}
}
3 changes: 1 addition & 2 deletions pingora-core/src/services/listening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ impl<A: ServerApp + Send + Sync + 'static> ServiceTrait for Service<A> {

futures::future::join_all(handlers).await;
self.listeners.cleanup();
self.app_logic.cleanup();
self.app_logic.async_cleanup().await;
self.app_logic.cleanup().await;
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion pingora-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ where
self.process_request(session, ctx).await
}

fn http_cleanup(&self) {
async fn http_cleanup(&self) {
// Notify all keepalived requests blocking on read_request() to abort
self.shutdown.notify_waiters();

Expand Down

0 comments on commit 3cd52fe

Please sign in to comment.