Skip to content

Commit 10b214a

Browse files
committed
Bugfix HTTP/2 flow control handling
There are two bugs fixed here, firslty negative flow control values are truthy (only 0 is False), and whilst negative flow control values are possible only positive ones should allow data to be sent. Secondly if the INITIAL_WINDOW_SIZE setting is changed (after the headers have been sent) h2 does not emit a WindowUpdated event (see python-hyper/h2#1193) yet the window should be updated. This should fix the intermittent (race-condition) errors with h2spec and the Trio worker.
1 parent 25348c2 commit 10b214a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

hypercorn/protocol/h2.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ async def _handle_events(self, events: List[h2.events.Event]) -> None:
137137
del self.streams[event.stream_id]
138138
elif isinstance(event, h2.events.WindowUpdated):
139139
await self._window_updated(event.stream_id)
140-
pass
140+
elif isinstance(event, h2.events.RemoteSettingsChanged):
141+
if h2.settings.SettingCodes.INITIAL_WINDOW_SIZE in event.changed_settings:
142+
await self._window_updated(None)
141143
elif isinstance(event, h2.events.ConnectionTerminated):
142144
await self.send(Closed())
143145
await self._flush()
@@ -149,7 +151,7 @@ async def _flush(self) -> None:
149151

150152
async def _send_data(self, stream_id: int, data: bytes) -> None:
151153
while True:
152-
while not self.connection.local_flow_control_window(stream_id):
154+
while self.connection.local_flow_control_window(stream_id) < 1:
153155
await self._wait_for_flow_control(stream_id)
154156

155157
chunk_size = min(len(data), self.connection.local_flow_control_window(stream_id))

0 commit comments

Comments
 (0)