Skip to content

Commit

Permalink
Fix cleanup of connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
thatnerdjosh committed Mar 31, 2024
1 parent 8d86551 commit 1bb6e3d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions shared/wait-for-psql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@

args = arg_parser.parse_args()

conn = None
start_time = time.time()
error = ''

while (time.time() - start_time) < args.timeout:
try:
if conn is not None:
conn.close()
conn = None # Reset conn to None

conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
error = ''
break
except psycopg2.OperationalError as e:
error = e
else:
conn.close()

time.sleep(1)

if error:
if conn:
conn.close()
else:
print("Database connection failure: %s" % error, file=sys.stderr)
sys.exit(1)

0 comments on commit 1bb6e3d

Please sign in to comment.