fix regression introduced in 70e08c880 (#4459)

This commit is contained in:
Maximilian Hils 2021-02-19 19:34:52 +01:00 committed by GitHub
parent 70e08c880c
commit cfaba15c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -628,16 +628,18 @@ class HttpLayer(layer.Layer):
h2_to_h1 = self.context.client.alpn == b"h2" and not conn_is_pending_or_h2
connection_suitable = (
event.connection_spec_matches(connection)
and connection.connected
and not h2_to_h1
)
if connection_suitable:
if connection in self.waiting_for_establishment:
self.waiting_for_establishment[connection].append(event)
else:
return
elif connection.connected:
stream = self.command_sources.pop(event)
yield from self.event_to_child(stream, GetHttpConnectionCompleted(event, (connection, None)))
return
else:
pass # the connection is at least half-closed already, we want a new one.
can_use_context_connection = (
self.context.server not in self.connections and

View File

@ -467,6 +467,29 @@ def test_max_concurrency(tctx):
assert req2.stream_id == 3
def test_stream_concurrent_get_connection(tctx):
"""Test that an immediate second request for the same domain does not trigger a second connection attempt."""
playbook, cff = start_h2_client(tctx)
playbook.hooks = False
server = Placeholder(Server)
data = Placeholder(bytes)
assert (playbook
>> DataReceived(tctx.client, cff.build_headers_frame(example_request_headers, flags=["END_STREAM"], stream_id=1).serialize())
<< (o := OpenConnection(server))
>> DataReceived(tctx.client, cff.build_headers_frame(example_request_headers, flags=["END_STREAM"], stream_id=3).serialize())
>> reply(None, to=o, side_effect=make_h2)
<< SendData(server, data)
)
frames = decode_frames(data())
assert [type(x) for x in frames] == [
hyperframe.frame.SettingsFrame,
hyperframe.frame.HeadersFrame,
hyperframe.frame.HeadersFrame,
]
def test_kill_stream(tctx):
"""Test that we can kill individual streams."""
playbook, cff = start_h2_client(tctx)