http: http2_sched_dispatch_tunnel fix 54/43554/2
authorMatus Fabian <[email protected]>
Fri, 15 Aug 2025 08:52:56 +0000 (04:52 -0400)
committerFlorin Coras <[email protected]>
Fri, 15 Aug 2025 12:40:51 +0000 (12:40 +0000)
Type: fix

Change-Id: I06f0da0d9805014b21c67da6113f2fc1d91a5408
Signed-off-by: Matus Fabian <[email protected]>
src/plugins/http/http2/http2.c
src/plugins/http/http_private.h

index 834d79e..5ba094b 100644 (file)
@@ -706,7 +706,6 @@ http2_sched_dispatch_tunnel (http2_req_t *req, http_conn_t *hc,
   max_write = clib_min (max_write, (u32) req->peer_window);
   max_write = clib_min (max_write, h2c->peer_window);
   max_write = clib_min (max_write, h2c->peer_settings.max_frame_size);
-  n_read = clib_min (max_write, max_read);
 
   if (req->stream_state == HTTP2_STREAM_STATE_HALF_CLOSED &&
       max_write >= max_read)
@@ -715,13 +714,16 @@ http2_sched_dispatch_tunnel (http2_req_t *req, http_conn_t *hc,
       session_transport_closed_notify (&req->base.connection);
       flags = HTTP2_FRAME_FLAG_END_STREAM;
     }
+
+  max_read = clib_min (max_write, max_read);
+  n_read = http_io_as_read_segs (&req->base, segs + 1, &n_segs, max_read);
+
   http2_frame_write_data_header (n_read, req->stream_id, flags, fh);
   segs[0].len = HTTP2_FRAME_HEADER_SIZE;
   segs[0].data = fh;
 
-  http_io_as_read_segs (&req->base, segs + 1, &n_segs, n_read);
-
   n_written = http_io_ts_write_segs (hc, segs, n_segs + 1, 0);
+  ASSERT (n_written == (HTTP2_FRAME_HEADER_SIZE + n_read));
   n_written -= HTTP2_FRAME_HEADER_SIZE;
   http_io_as_drain (&req->base, n_written);
   req->peer_window -= n_written;
@@ -1683,12 +1685,12 @@ http2_req_state_tunnel_rx (http_conn_t *hc, http2_req_t *req,
 {
   u32 max_enq;
 
-  HTTP_DBG (1, "tunnel received data from peer");
+  HTTP_DBG (1, "tunnel received data from peer %lu", req->payload_len);
 
   max_enq = http_io_as_max_write (&req->base);
   if (max_enq < req->payload_len)
     {
-      clib_warning ("app's rx fifo full");
+      clib_warning ("not enough space in app fifo (%lu)", max_enq);
       http2_stream_error (hc, req, HTTP2_ERROR_INTERNAL_ERROR, sp);
       return HTTP_SM_STOP;
     }
index daa9d0a..6036b5a 100644 (file)
@@ -637,7 +637,7 @@ http_io_as_peek (http_req_t *req, u8 *buf, u32 len, u32 offset)
   return (u32) n_read;
 }
 
-always_inline void
+always_inline u32
 http_io_as_read_segs (http_req_t *req, svm_fifo_seg_t *segs, u32 *n_segs,
                      u32 max_bytes)
 {
@@ -645,6 +645,7 @@ http_io_as_read_segs (http_req_t *req, svm_fifo_seg_t *segs, u32 *n_segs,
   session_t *as = session_get_from_handle (req->hr_pa_session_handle);
   n_read = svm_fifo_segments (as->tx_fifo, 0, segs, n_segs, max_bytes);
   ASSERT (n_read > 0);
+  return (u32) n_read;
 }
 
 always_inline void