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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2189: Wakeup pending waiters #2329

Merged
merged 9 commits into from
Oct 17, 2017
3 changes: 3 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ def connect(self, req):
if self._closed:
proto.close()
raise ClientConnectionError("Connector is closed.")
except:
self._release_waiter()
raise
finally:
if not self._closed:
self._acquired.remove(placeholder)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,49 @@ def test_force_close_and_explicit_keep_alive(loop):
assert conn


@asyncio.coroutine
def test_error_on_connection(loop):
conn = aiohttp.BaseConnector(limit=1, loop=loop)

req = mock.Mock()
req.connection_key = 'key'
proto = mock.Mock()
i = 0

fut = helpers.create_future(loop=loop)
exc = OSError()

@asyncio.coroutine
def create_connection(req):
nonlocal i
i += 1
if i == 1:
yield from fut
raise exc
elif i == 2:
return proto

conn._create_connection = create_connection

t1 = asyncio.ensure_future(conn.connect(req))
t2 = asyncio.ensure_future(conn.connect(req))
yield from asyncio.sleep(0, loop=loop)
assert not t1.done()
assert not t2.done()
assert len(conn._acquired_per_host['key']) == 1

fut.set_result(None)
with pytest.raises(OSError):
yield from t1

ret = yield from t2
assert len(conn._acquired_per_host['key']) == 1

assert ret._key == 'key'
assert ret.protocol == proto
assert proto in conn._acquired


@asyncio.coroutine
def test_tcp_connector(test_client, loop):
@asyncio.coroutine
Expand Down