pingora icon indicating copy to clipboard operation
pingora copied to clipboard

Add `async_cleanup()` method to `ServerApp` trait

Open YHM404 opened this issue 10 months ago • 1 comments

Motivation: In the current implementation of ServerApp trait (name the trait if possible), we have a synchronous method cleanup designed to clean up resources when a service is stopped. However, as our application evolves and embraces more asynchronous operations, the need for an asynchronous cleanup method has become apparent. This addition will allow for non-blocking resource cleanup, aligning with the asynchronous nature of our other operations.

Changes: Added async fn async_cleanup(): Introduced a new asynchronous function, async_cleanup, to the ServerApp trait. This method is intended to asynchronously clean up resources, complementing the existing cleanup method. Compatibility Considerations: To ensure backward compatibility and minimize disruption, the existing cleanup method remains unchanged. Users can choose between cleanup for synchronous operations and async_cleanup for asynchronous operations, depending on their use case.

YHM404 avatar Apr 09 '24 14:04 YHM404

Discussing internally: though it would be a breaking change, we thought it would be preferable to make the existing cleanup() an async function for simplicity, especially while we are still in v0. Does that resolve your issue, and would you be able to make that change?

I have made the corresponding modifications to the PR. This should resolve my issue. Thank you for your reply.

YHM404 avatar Apr 20 '24 04:04 YHM404

This change is now available via https://github.com/cloudflare/pingora/commit/42b02241295a3a89bf44014aa991c88fa9e86e1f. Thanks for the contribution.

eaufavor avatar May 10 '24 23:05 eaufavor