Skip to content

Do not attempt to connect to Unix sockets on Windows when host is not set #192

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

Merged
merged 1 commit into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions asyncpg/connect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import collections
import getpass
import os
import platform
import socket
import struct
import time
Expand Down Expand Up @@ -40,6 +41,9 @@
])


_system = platform.uname().system


def _parse_connect_dsn_and_args(*, dsn, host, port, user,
password, database, ssl, connect_timeout,
server_settings):
Expand Down Expand Up @@ -123,9 +127,13 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
if host is None:
host = os.getenv('PGHOST')
if not host:
host = ['/tmp', '/private/tmp',
'/var/pgsql_socket', '/run/postgresql',
'localhost']
if _system == 'Windows':
host = ['localhost']
else:
host = ['/tmp', '/private/tmp',
'/var/pgsql_socket', '/run/postgresql',
'localhost']

if not isinstance(host, list):
host = [host]

Expand Down
6 changes: 6 additions & 0 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ async def test_connection_ssl_unix(self):
loop=self.loop,
ssl=ssl_context)

async def test_connection_implicit_host(self):
conn_spec = self.cluster.get_connection_spec()
con = await asyncpg.connect(
port=conn_spec['port'], database='postgres', loop=self.loop)
await con.close()


@unittest.skipIf(os.environ.get('PGHOST'), 'unmanaged cluster')
class TestSSLConnection(tb.ConnectedTestCase):
Expand Down