From fda581d846f25755099e523d4c3329907bc0e674 Mon Sep 17 00:00:00 2001 From: vladyslav Date: Wed, 6 May 2026 13:25:11 +0300 Subject: [PATCH] Allow sending 0-byte DATA frames when flow-control window is negative --- src/h2/connection.py | 4 ++-- src/h2/stream.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/h2/connection.py b/src/h2/connection.py index 6c5122024..835ec479a 100644 --- a/src/h2/connection.py +++ b/src/h2/connection.py @@ -888,7 +888,7 @@ def send_data(self, "Frame size on stream ID %d is %d", stream_id, frame_size, ) - if frame_size > self.local_flow_control_window(stream_id): + if frame_size > 0 and frame_size > self.local_flow_control_window(stream_id): msg = f"Cannot send {frame_size} bytes, flow control window is {self.local_flow_control_window(stream_id)}" raise FlowControlError(msg) if frame_size > self.max_outbound_frame_size: @@ -907,7 +907,7 @@ def send_data(self, "Outbound flow control window size is %d", self.outbound_flow_control_window, ) - assert self.outbound_flow_control_window >= 0 + assert self.outbound_flow_control_window >= 0 or frame_size == 0 def end_stream(self, stream_id: int) -> None: """ diff --git a/src/h2/stream.py b/src/h2/stream.py index 7eb436159..9b5bce789 100644 --- a/src/h2/stream.py +++ b/src/h2/stream.py @@ -981,7 +981,7 @@ def send_data(self, # Subtract flow_controlled_length to account for possible padding self.outbound_flow_control_window -= df.flow_controlled_length - assert self.outbound_flow_control_window >= 0 + assert self.outbound_flow_control_window >= 0 or df.flow_controlled_length == 0 return [df]