Skip to content

Commit

Permalink
Bugfix HTTP/2 flow control handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pgjones committed Jul 8, 2019
1 parent 25348c2 commit 10b214a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hypercorn/protocol/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ async def _handle_events(self, events: List[h2.events.Event]) -> None:
del self.streams[event.stream_id]
elif isinstance(event, h2.events.WindowUpdated):
await self._window_updated(event.stream_id)
pass
elif isinstance(event, h2.events.RemoteSettingsChanged):
if h2.settings.SettingCodes.INITIAL_WINDOW_SIZE in event.changed_settings:
await self._window_updated(None)
elif isinstance(event, h2.events.ConnectionTerminated):
await self.send(Closed())
await self._flush()
Expand All @@ -149,7 +151,7 @@ async def _flush(self) -> None:

async def _send_data(self, stream_id: int, data: bytes) -> None:
while True:
while not self.connection.local_flow_control_window(stream_id):
while self.connection.local_flow_control_window(stream_id) < 1:
await self._wait_for_flow_control(stream_id)

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

0 comments on commit 10b214a

Please sign in to comment.