Skip to content

Commit 1bb6e3d

Browse files
committed
Fix cleanup of connections.
1 parent 8d86551 commit 1bb6e3d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

shared/wait-for-psql.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@
1616

1717
args = arg_parser.parse_args()
1818

19+
conn = None
1920
start_time = time.time()
21+
error = ''
22+
2023
while (time.time() - start_time) < args.timeout:
2124
try:
25+
if conn is not None:
26+
conn.close()
27+
conn = None # Reset conn to None
28+
2229
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
23-
error = ''
2430
break
2531
except psycopg2.OperationalError as e:
2632
error = e
27-
else:
28-
conn.close()
33+
2934
time.sleep(1)
3035

31-
if error:
36+
if conn:
37+
conn.close()
38+
else:
3239
print("Database connection failure: %s" % error, file=sys.stderr)
3340
sys.exit(1)

0 commit comments

Comments
 (0)