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

feat: add shutdown method to AsyncDB DB and Runner #250

Merged
merged 6 commits into from
Feb 11, 2025
Merged

Conversation

BugenZhao
Copy link
Collaborator

@BugenZhao BugenZhao commented Feb 5, 2025

Changes

Add shutdown method to AsyncDB. Implement it for all engines. Adopt it in binary.

Motivation

Previously we have a Drop impl for Postgres which directly aborts the background connection. This is not good as there's no chance for the pgwire protocol to gracefully shutdown itself. As a result, we see failed to read message: unexpected end of file every time a test case (file) completes in the server side.

Simply removing this Drop impl and letting the connection run to completion in the background resolves this issue. However, let's get one step further and propose a general design to all kinds of database engines by manually specifying and calling the shutdown method.


Signed-off-by: Bugen Zhao [email protected]

Signed-off-by: Bugen Zhao <[email protected]>
@BugenZhao BugenZhao requested review from skyzh and xxchan February 5, 2025 09:02
pub fn pg_client(&self) -> &tokio_postgres::Client {
&self.client
pub fn client(&self) -> &tokio_postgres::Client {
&self.conn.as_ref().expect("fuck").0
Copy link
Member

Choose a reason for hiding this comment

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

?

Comment on lines 538 to 543
impl<D: AsyncDB, M: MakeConnection<Conn = D>> Drop for Runner<D, M> {
fn drop(&mut self) {
tracing::debug!("shutting down runner...");
block_on(self.conn.shutdown_all());
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Would block_on in drop be problematic? (If not, why don't we simply do it in impl Drop for Postgres without introducing a separate shutdown?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good point... 😕

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to always let the caller handle shutdown.

@xxchan
Copy link
Member

xxchan commented Feb 6, 2025

As a result, we see failed to read message: unexpected end of file every time a test case (file) completes in the server side.

Nice catch 👍

Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
@skyzh
Copy link
Member

skyzh commented Feb 7, 2025

unfortunately we need to bump the version :(

@BugenZhao BugenZhao requested a review from xxchan February 11, 2025 06:54
@BugenZhao BugenZhao changed the title feat: add shutdown method to AsyncDB feat: add shutdown method to AsyncDB DB and Runner Feb 11, 2025
@xxchan xxchan merged commit 89d0d3c into main Feb 11, 2025
4 checks passed
@xxchan xxchan deleted the bz/shutdown branch February 11, 2025 07:26
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.

3 participants