Skip to content

Commit 06aa5c9

Browse files
authored
Merge pull request #1225 from mihau/fix-window-update-on-closed-streams
ignore WINDOW_UPDATE frames on removed or non-existent stream
2 parents 419142f + 4d4e841 commit 06aa5c9

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

h2/connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,10 +1733,13 @@ def _receive_window_update_frame(self, frame):
17331733
)
17341734

17351735
if frame.stream_id:
1736-
stream = self._get_stream_by_id(frame.stream_id)
1737-
frames, stream_events = stream.receive_window_update(
1738-
frame.window_increment
1739-
)
1736+
try:
1737+
stream = self._get_stream_by_id(frame.stream_id)
1738+
frames, stream_events = stream.receive_window_update(
1739+
frame.window_increment
1740+
)
1741+
except StreamClosedError:
1742+
return [], events
17401743
else:
17411744
# Increment our local flow control window.
17421745
self.outbound_flow_control_window = guard_increment_window(

test/test_closed_streams.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ def test_receive_window_update_on_closed_stream(self, frame_factory):
178178
events = c.receive_data(window_update_frame.serialize())
179179
assert not events
180180

181+
# Getting open_inbound_streams property will trigger stream accounting
182+
# which results in removing closed streams.
183+
c.open_inbound_streams
184+
185+
# Another window_update_frame is received for stream 1
186+
events = c.receive_data(window_update_frame.serialize())
187+
assert not events
188+
181189

182190
class TestStreamsClosedByEndStream(object):
183191
example_request_headers = [

0 commit comments

Comments
 (0)