diff --git a/aiopg/connection.py b/aiopg/connection.py index ca32bda0..dfbec5a7 100755 --- a/aiopg/connection.py +++ b/aiopg/connection.py @@ -834,10 +834,13 @@ def _ready(weak_self: "weakref.ref[Any]") -> None: self._writing = False elif state == psycopg2.extensions.POLL_WRITE: if not self._writing: - self._loop.add_writer( - self._fileno, self._ready, weak_self # type: ignore - ) - self._writing = True + try: + self._loop.add_writer( + self._fileno, self._ready, weak_self # type: ignore + ) + self._writing = True + except OSError as e: + waiter.set_exception(e) elif state == psycopg2.extensions.POLL_ERROR: self._fatal_error( "Fatal error on aiopg connection: " diff --git a/setup.py b/setup.py index 6cd4ccef..812a4440 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages -install_requires = ["psycopg2-binary>=2.8.4", "async_timeout>=3.0,<4.0"] +install_requires = ["psycopg2-binary>=2.8.4", "async_timeout>=3.0,<5.0"] extras_require = {"sa": ["sqlalchemy[postgresql_psycopg2binary]>=1.3,<1.5"]}