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

[FIX] runbot: warn when a local pg backend cannot be terminated #733

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from collections import defaultdict
from pathlib import Path
from psycopg2 import sql
from psycopg2.errors import InsufficientPrivilege
import getpass

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -876,7 +877,11 @@ def filter_patterns(patterns, default, all):
def _local_pg_dropdb(self, dbname):
with local_pgadmin_cursor() as local_cr:
pid_col = 'pid' if local_cr.connection.server_version >= 90200 else 'procpid'
query = 'SELECT pg_terminate_backend({}) FROM pg_stat_activity WHERE datname=%s'.format(pid_col)
try:
query = 'SELECT pg_terminate_backend({}) FROM pg_stat_activity WHERE datname=%s'.format(pid_col)
except InsufficientPrivilege:
_logger.warning('Cannot terminate backend process for %s (maybe a root psql console is accessing the database).', dbname)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could maybe add a runbot warning? this could be like that for a while.
I'm also worried because it could wait for a while an slow down the loop. Not sure
We could add a mechanism like pull_info_failures to avoid spamming the log and avoid useless retry. Just keeping a list of failed database in memory maybe

return
local_cr.execute(query, [dbname])
local_cr.execute('DROP DATABASE IF EXISTS "%s"' % dbname)
# cleanup filestore
Expand Down