Skip to content

Commit 73bea23

Browse files
aftersnowwinters.zc
and
winters.zc
authored
fix: panic in when there is connection window available, but not stream (#657)
We met the panic in our production environment, so handle this panic condition before panic. The stack backtrace: Co-authored-by: winters.zc <[email protected]>
1 parent b84c244 commit 73bea23

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/proto/streams/flow_control.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ impl FlowControl {
173173
self.available
174174
);
175175

176-
// Ensure that the argument is correct
177-
assert!(self.window_size >= sz as usize);
178-
179-
// Update values
180-
self.window_size -= sz;
181-
self.available -= sz;
176+
// If send size is zero it's meaningless to update flow control window
177+
if sz > 0 {
178+
// Ensure that the argument is correct
179+
assert!(self.window_size >= sz as usize);
180+
181+
// Update values
182+
self.window_size -= sz;
183+
self.available -= sz;
184+
}
182185
}
183186
}
184187

src/proto/streams/prioritize.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,14 @@ impl Prioritize {
744744
// capacity at this point.
745745
debug_assert!(len <= self.flow.window_size());
746746

747+
// Check if the stream level window the peer knows is available. In some
748+
// scenarios, maybe the window we know is available but the window which
749+
// peer knows is not.
750+
if len > 0 && len > stream.send_flow.window_size() {
751+
stream.pending_send.push_front(buffer, frame.into());
752+
continue;
753+
}
754+
747755
tracing::trace!(len, "sending data frame");
748756

749757
// Update the flow control

0 commit comments

Comments
 (0)