Skip to content

Commit 7cf68d8

Browse files
committed
Avoid constructing SSL context when only Unix sockets are used
1 parent 0207bcc commit 7cf68d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

asyncpg/connect_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
380380
passfile=passfile)
381381

382382
addrs = []
383+
have_tcp_addrs = False
383384
for h, p in zip(host, port):
384385
if h.startswith('/'):
385386
# UNIX socket name
@@ -389,6 +390,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
389390
else:
390391
# TCP host/port
391392
addrs.append((h, p))
393+
have_tcp_addrs = True
392394

393395
if not addrs:
394396
raise ValueError(
@@ -397,7 +399,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
397399
if ssl is None:
398400
ssl = os.getenv('PGSSLMODE')
399401

400-
if ssl is None:
402+
if ssl is None and have_tcp_addrs:
401403
ssl = 'prefer'
402404

403405
# ssl_is_advisory is only allowed to come from the sslmode parameter.

0 commit comments

Comments
 (0)