Skip to content

use pg-ctl stop to cleanup before killing the process #16

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DShau22
Copy link

@DShau22 DShau22 commented Mar 28, 2024

Proposed fix for this issue

Ran make test to confirm that all existing tests still pass, and make check for formatting

Docs on pg-ctl for reference

@DShau22 DShau22 requested a review from davvid March 30, 2024 16:19
Copy link
Collaborator

@davvid davvid left a comment

Choose a reason for hiding this comment

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

one last request might be to rebase and squash these two commit together so that there's only one remaining, but that's mostly aesthetic. We'll let @ugtar do the final merge, tho.

@DShau22 DShau22 force-pushed the fix/use-pg-ctl-in-cleanup branch from e3c64bd to f055454 Compare March 30, 2024 23:20
@DShau22
Copy link
Author

DShau22 commented Mar 30, 2024

Just squashed and force pushed!

@DShau22 DShau22 requested a review from davvid March 30, 2024 23:21
@@ -358,6 +359,8 @@ def cleanup(self):
stdout=subprocess.DEVNULL,
)
elif self.pg_process:
pg_stop_cmd = ['pg_ctl', 'stop', '-D', self.pg_data_dir, '-m' 'fast']
Copy link
Owner

Choose a reason for hiding this comment

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

We need to be able to override pg_ctl in the same way that we do postgres or initdb, in the case the user is using an alternative postgres install that is not in the PATH. This needs a default, and an argument (plus said default) in the constructor. See for example DEFAULT_POSTGRES or DEFAULT_INITDB

@@ -358,6 +359,8 @@ def cleanup(self):
stdout=subprocess.DEVNULL,
)
elif self.pg_process:
pg_stop_cmd = ['pg_ctl', 'stop', '-D', self.pg_data_dir, '-m' 'fast']
self.run_cmd(pg_stop_cmd, level=2, bg=True).wait()
Copy link
Owner

Choose a reason for hiding this comment

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

I think since run_cmd with level 2 can potentially produce stdout and stderr, instead of .wait() we should call .communicate(). Also, since this command can be caught by the pg process or hang, we should have a timeout at which point we give up and call kill() anyway. Maybe 10 seconds?
The python docs have an example of how to do this properly, catching the TimeoutExpired exception https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate

@ugtar
Copy link
Owner

ugtar commented Apr 19, 2024

thanks @DShau22, sorry I took so long to get to this, I've been swamped at dayjob

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