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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect_timeout fix #360

Merged
merged 2 commits into from
Dec 4, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions aiomysql/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,21 @@ async def _connect(self):
try:
if self._unix_socket and self._host in ('localhost', '127.0.0.1'):
self._reader, self._writer = await \
asyncio.open_unix_connection(self._unix_socket,
loop=self._loop)
asyncio.wait_for(
asyncio.open_unix_connection(
self._unix_socket,
loop=self._loop),
timeout=self.connect_timeout)
self.host_info = "Localhost via UNIX socket: " + \
self._unix_socket
else:
self._reader, self._writer = await \
asyncio.open_connection(self._host, self._port,
loop=self._loop)
asyncio.wait_for(
asyncio.open_connection(
self._host,
self._port,
loop=self._loop),
timeout=self.connect_timeout)
self._set_keep_alive()
self.host_info = "socket %s:%d" % (self._host, self._port)

Expand Down
2 changes: 1 addition & 1 deletion aiomysql/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ async def _show_warnings(self, conn):
ProgrammingError = ProgrammingError
NotSupportedError = NotSupportedError

async def __aiter__(self):
def __aiter__(self):
return self

async def __anext__(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def fill_my_cnf(self):
with open(path2, 'w') as f2:
f2.write(tmpl.format_map(self.__dict__))

@run_until_complete
def test_connect_timeout(self):
# All exceptions are caught and raised as operational errors
with self.assertRaises(aiomysql.OperationalError):
yield from self.connect(connect_timeout=0.000000000001)

@run_until_complete
def test_config_file(self):
self.fill_my_cnf()
Expand Down