You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2026/10/02 20:56:09 UTC

(trafficserver) branch master updated: Deliver H2 END_STREAM that arrives while read is throttled (#13780)

This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 00a22f2081 Deliver H2 END_STREAM that arrives while read is throttled (#13780)
00a22f2081 is described below

commit 00a22f20810ce5fd6ac4ca297861e5d39db11aee
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Fri Oct 2 15:56:02 2026 -0500

    Deliver H2 END_STREAM that arrives while read is throttled (#13780)
    
    With HTTP/2 to origin, an HTTP/1.1 client receiving a re-chunked
    response larger than the buffer water mark could get the whole body
    but never the terminating chunk. The chunked tunnel disables the
    origin stream's read VIO when its output backs up. If END_STREAM
    arrived during that window, on a DATA frame or on trailers, the stream
    dropped the event that ends the read, and re-enabling the VIO only
    reopened the flow-control window. The transaction then sat until a
    timeout, logging "HTTP/2 unknown case" once a second.
    
    This patch has the stream remember the final read event it could not
    deliver because its read VIO was disabled, and schedule that same event
    once the consumer re-enables the VIO, deferring it again if the
    consumer has throttled once more by the time it is dispatched. The
    chunked flow-control AuTest gains an HTTP/2 origin case, plus a custom
    origin that ends the stream inside the throttle window on a DATA frame
    and on trailers.
    
    Fixes: #13777
    
    Co-authored-by: Claude Opus 5.5 Medium
---
 include/proxy/http2/Http2Stream.h                  |  22 ++-
 src/proxy/http2/Http2ConnectionState.cc            |  27 ++--
 src/proxy/http2/Http2Stream.cc                     |  67 +++++++--
 .../chunked_encoding/chunked_flow_control.test.py  |  74 +++++++++-
 .../chunked_encoding/h2_end_stream_origin.py       | 120 +++++++++++++++++
 .../chunked_h2_origin_flow_control.replay.yaml     | 150 +++++++++++++++++++++
 6 files changed, 427 insertions(+), 33 deletions(-)

diff --git a/include/proxy/http2/Http2Stream.h b/include/proxy/http2/Http2Stream.h
index fdb2bcc2bf..5b41a4eb22 100644
--- a/include/proxy/http2/Http2Stream.h
+++ b/include/proxy/http2/Http2Stream.h
@@ -92,6 +92,7 @@ public:
   void           update_write_request(bool send_update);
 
   void                  signal_read_event(int event);
+  void                  signal_final_read_event(int event);
   static constexpr auto CALL_UPDATE = true;
   void                  signal_write_event(int event, bool call_update = CALL_UPDATE);
 
@@ -246,7 +247,11 @@ private:
 #endif
   VIO  read_vio;
   VIO  write_vio;
-  bool _read_event_paused = false; ///< The read VIO is intentionally gated by a zero-byte read.
+  bool _read_event_paused   = false;         ///< The read VIO is intentionally gated by a zero-byte read.
+  int  _deferred_read_event = VC_EVENT_NONE; ///< A final read event that arrived while the consumer had the read VIO disabled.
+
+  bool        _is_read_gated() const;
+  static bool _is_final_read_event(int event);
 
   History<HISTORY_DEFAULT_SIZE>                                                           _history;
   Milestones<Http2StreamMilestone, static_cast<size_t>(Http2StreamMilestone::LAST_ENTRY)> _milestones;
@@ -524,10 +529,23 @@ Http2Stream::read_vio_writer() const
   return this->read_vio.get_writer();
 }
 
+/** Whether @a event ends the read side, so it must go through signal_final_read_event() rather than be dropped. */
+inline bool
+Http2Stream::_is_final_read_event(int event)
+{
+  return event == VC_EVENT_READ_COMPLETE || event == VC_EVENT_EOS;
+}
+
+inline bool
+Http2Stream::_is_read_gated() const
+{
+  return this->_read_event_paused || this->read_vio.nbytes == 0;
+}
+
 inline bool
 Http2Stream::is_read_enabled() const
 {
-  return !this->_read_event_paused && this->read_vio.nbytes != 0 && !this->read_vio.is_disabled();
+  return !this->_is_read_gated() && !this->read_vio.is_disabled();
 }
 
 inline void
diff --git a/src/proxy/http2/Http2ConnectionState.cc b/src/proxy/http2/Http2ConnectionState.cc
index 11af722e8a..abb0e7853c 100644
--- a/src/proxy/http2/Http2ConnectionState.cc
+++ b/src/proxy/http2/Http2ConnectionState.cc
@@ -184,9 +184,7 @@ Http2ConnectionState::rcv_data_frame(const Http2Frame &frame)
         return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_NONE);
       }
 
-      if (stream->is_read_enabled()) {
-        stream->signal_read_event(VC_EVENT_READ_COMPLETE);
-      }
+      stream->signal_final_read_event(VC_EVENT_READ_COMPLETE);
 
       return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_NONE);
     }
@@ -263,22 +261,19 @@ Http2ConnectionState::rcv_data_frame(const Http2Frame &frame)
   myreader->writer()->dealloc_reader(myreader);
 
   if (frame.header().flags & HTTP2_FLAGS_DATA_END_STREAM) {
-    // TODO: set total written size to read_vio.nbytes
     stream->set_read_done();
   }
 
-  if (stream->is_read_enabled()) {
-    if (frame.header().flags & HTTP2_FLAGS_DATA_END_STREAM) {
-      if (this->get_peer_stream_count() > 1 && this->get_local_rwnd() == 0) {
-        // This final DATA frame for this stream consumed all the bytes for the
-        // session window. Send a WINDOW_UPDATE frame in order to open up the
-        // session window for other streams.
-        restart_receiving(nullptr);
-      }
-      stream->signal_read_event(VC_EVENT_READ_COMPLETE);
-    } else {
-      stream->signal_read_event(VC_EVENT_READ_READY);
-    }
+  if (frame.header().flags & HTTP2_FLAGS_DATA_END_STREAM) {
+    if (stream->is_read_enabled() && this->get_peer_stream_count() > 1 && this->get_local_rwnd() == 0) {
+      // This final DATA frame for this stream consumed all the bytes for the
+      // session window. Send a WINDOW_UPDATE frame in order to open up the
+      // session window for other streams.
+      restart_receiving(nullptr);
+    }
+    stream->signal_final_read_event(VC_EVENT_READ_COMPLETE);
+  } else if (stream->is_read_enabled()) {
+    stream->signal_read_event(VC_EVENT_READ_READY);
   }
 
   return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_NONE);
diff --git a/src/proxy/http2/Http2Stream.cc b/src/proxy/http2/Http2Stream.cc
index 0d8b2137af..232c2ca4f1 100644
--- a/src/proxy/http2/Http2Stream.cc
+++ b/src/proxy/http2/Http2Stream.cc
@@ -184,7 +184,12 @@ Http2Stream::main_event_handler(int event, void *edata)
   reentrancy_count++;
   if (e == _read_vio_event) {
     _read_vio_event = nullptr;
-    this->signal_read_event(e->callback_event);
+    // A final event retried after a mutex miss must survive a throttle that started meanwhile.
+    if (_is_final_read_event(e->callback_event)) {
+      this->signal_final_read_event(e->callback_event);
+    } else {
+      this->signal_read_event(e->callback_event);
+    }
     reentrancy_count--;
     return 0;
   } else if (e == _write_vio_event) {
@@ -255,7 +260,12 @@ Http2Stream::main_event_handler(int event, void *edata)
     _timeout.update_inactivity();
     if (e->cookie == &read_vio) {
       if (read_vio.mutex && read_vio.cont && this->_sm) {
-        this->signal_read_event(event);
+        // A completion scheduled by reenable() must survive the consumer throttling again before it is dispatched.
+        if (_is_final_read_event(event)) {
+          this->signal_final_read_event(event);
+        } else {
+          this->signal_read_event(event);
+        }
       }
     } else {
       this->update_read_request(true);
@@ -389,11 +399,14 @@ Http2Stream::send_headers(Http2ConnectionState & /* cstate ATS_UNUSED */)
         // get its content from the VIO
         // This can break if the implementation
         // changes.
-        this->signal_read_event(VC_EVENT_EOS);
+        //
+        // If the consumer has throttled the read VIO, the EOS waits for
+        // reenable(), so nothing is flushed until the consumer drains.
+        this->signal_final_read_event(VC_EVENT_EOS);
       } else {
         // Request headers.
         this->read_vio.ndone = this->read_vio.nbytes;
-        this->signal_read_event(VC_EVENT_READ_COMPLETE);
+        this->signal_final_read_event(VC_EVENT_READ_COMPLETE);
       }
     } else {
       // End of header but not end of stream, must have some body frames coming
@@ -520,13 +533,14 @@ Http2Stream::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
     read_vio.buffer.clear();
   }
 
-  read_vio.mutex           = c ? c->mutex : this->mutex;
-  read_vio.cont            = c;
-  read_vio.nbytes          = nbytes;
-  read_vio.ndone           = gated_ndone;
-  read_vio.vc_server       = this;
-  read_vio.op              = VIO::READ;
-  this->_read_event_paused = nbytes == 0;
+  read_vio.mutex             = c ? c->mutex : this->mutex;
+  read_vio.cont              = c;
+  read_vio.nbytes            = nbytes;
+  read_vio.ndone             = gated_ndone;
+  read_vio.vc_server         = this;
+  read_vio.op                = VIO::READ;
+  this->_read_event_paused   = nbytes == 0;
+  this->_deferred_read_event = VC_EVENT_NONE;
 
   if (this->_read_event_paused) {
     if (this->_read_vio_event) {
@@ -761,7 +775,7 @@ Http2Stream::update_read_request(bool call_update)
   ink_release_assert(this->_thread == this_ethread());
 
   SCOPED_MUTEX_LOCK(lock, read_vio.mutex, this_ethread());
-  if (this->_read_event_paused || read_vio.nbytes == 0 || read_vio.is_disabled()) {
+  if (this->_is_read_gated() || read_vio.is_disabled()) {
     return;
   }
 
@@ -934,8 +948,7 @@ void
 Http2Stream::signal_read_event(int event)
 {
   if (this->_sm == nullptr || this->read_vio.cont == nullptr || this->read_vio.cont->mutex == nullptr ||
-      this->read_vio.op == VIO::NONE || this->_read_event_paused || this->read_vio.nbytes == 0 || this->read_vio.is_disabled() ||
-      this->terminate_stream) {
+      this->read_vio.op == VIO::NONE || this->_is_read_gated() || this->read_vio.is_disabled() || this->terminate_stream) {
     return;
   }
 
@@ -959,6 +972,25 @@ Http2Stream::signal_read_event(int event)
   terminate_if_possible();
 }
 
+/** Signal the event that ends the read side, or hold it until reenable() if the consumer has the read VIO disabled.
+
+  A consumer that throttles its producer disables the read VIO. The END_STREAM that arrives during that
+  window is the only end-of-read signal the stream will see, so it must not be dropped.
+ */
+void
+Http2Stream::signal_final_read_event(int event)
+{
+  if (this->_is_read_gated()) {
+    return;
+  }
+  if (this->read_vio.is_disabled()) {
+    Http2StreamDebug("defer %s until the read VIO is re-enabled", get_vc_event_name(event));
+    this->_deferred_read_event = event;
+    return;
+  }
+  this->signal_read_event(event);
+}
+
 void
 Http2Stream::signal_write_event(int event, bool call_update)
 {
@@ -1047,6 +1079,13 @@ Http2Stream::reenable(VIO *vio)
       SCOPED_MUTEX_LOCK(ssn_lock, _proxy_ssn->mutex, this_ethread());
       Http2ConnectionState &connection_state = this->get_connection_state();
       connection_state.restart_receiving(this);
+      if (this->_deferred_read_event != VC_EVENT_NONE && this->_sm != nullptr && this->read_vio.cont != nullptr) {
+        // Schedule rather than call back: the consumer re-enabling us is still on the stack. If it throttles
+        // again before the event is dispatched, main_event_handler() defers the event once more.
+        this->read_event = this->send_tracked_event(this->read_event, this->_deferred_read_event, &this->read_vio);
+        Http2StreamDebug("rescheduled deferred %s", get_vc_event_name(this->_deferred_read_event));
+        this->_deferred_read_event = VC_EVENT_NONE;
+      }
     }
   }
 }
diff --git a/tests/gold_tests/chunked_encoding/chunked_flow_control.test.py b/tests/gold_tests/chunked_encoding/chunked_flow_control.test.py
index c1ee966174..5648e07b5e 100644
--- a/tests/gold_tests/chunked_encoding/chunked_flow_control.test.py
+++ b/tests/gold_tests/chunked_encoding/chunked_flow_control.test.py
@@ -1,5 +1,5 @@
 '''
-Regression test: chunked-origin -> HTTP/2 client dechunk flow-control throttle.
+Regression tests for the chunked-tunnel flow-control throttle.
 '''
 #  Licensed to the Apache Software Foundation (ASF) under one
 #  or more contributor license agreements.  See the NOTICE file
@@ -17,8 +17,80 @@ Regression test: chunked-origin -> HTTP/2 client dechunk flow-control throttle.
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
+import os
+import sys
+
+from ports import get_port
+
 Test.Summary = __doc__
 
 Test.ATSReplayTest(replay_file="replays/chunked_h1_flow_control.replay.yaml")
 Test.ATSReplayTest(replay_file="replays/chunked_h2_flow_control.replay.yaml")
+Test.ATSReplayTest(replay_file="replays/chunked_h2_origin_flow_control.replay.yaml")
 Test.ATSReplayTest(replay_file="replays/chunked_passthru_flow_control.replay.yaml")
+
+# A custom HTTP/2 origin sends the response header, waits for ATS to start the
+# tunnel, then writes a body that pushes the chunked output buffer past high
+# water together with the end of the stream. END_STREAM therefore arrives while
+# the tunnel has the producer throttled. Each case gets its own ATS so its log
+# assertions cannot be satisfied by another case.
+ssl_dir = os.path.join(Test.Variables.AtsTestToolsDir, 'ssl')
+
+h2_origin = Test.Processes.Process('h2-end-stream-origin')
+h2_origin_port = get_port(h2_origin, 'https_port')
+h2_origin.Setup.Copy(os.path.join(ssl_dir, 'server.pem'))
+h2_origin.Setup.Copy(os.path.join(ssl_dir, 'server.key'))
+h2_origin.Command = f'{sys.executable} {Test.TestDirectory}/h2_end_stream_origin.py {h2_origin_port} server.pem server.key'
+h2_origin.Ready = When.PortOpen(h2_origin_port)
+h2_origin.Streams.stdout = Testers.ExcludesExpression('queue_body_failed', 'The origin must queue every response body.')
+
+
+def make_ts(name: str, deferred_event: str | None):
+    """Configure an ATS for one case, expecting the deferral of deferred_event if given."""
+    ts = Test.MakeATSProcess(name, enable_cache=False)
+    ts.Disk.records_config.update(
+        {
+            'proxy.config.diags.debug.enabled': 1,
+            'proxy.config.diags.debug.tags': 'http_tunnel|http2_stream',
+            'proxy.config.http.default_buffer_water_mark': 4096,
+            'proxy.config.ssl.client.alpn_protocols': 'h2,http/1.1',
+            'proxy.config.ssl.client.verify.server.policy': 'PERMISSIVE',
+            # One origin connection per request, so each starts with full flow-control windows.
+            'proxy.config.http.server_session_sharing.match': 'none',
+            # A dropped END_STREAM stalls the tunnel until this timeout, which then
+            # finishes the response. The client gives up well before it fires.
+            'proxy.config.http.transaction_no_activity_timeout_out': 10,
+        })
+    ts.Disk.traffic_out.Content = Testers.ExcludesExpression(
+        r'producer_handler \[http server VC_EVENT_INACTIVITY_TIMEOUT', 'No response may stall until the origin timeout.')
+    if deferred_event is not None:
+        ts.Disk.traffic_out.Content += Testers.ContainsExpression(
+            f'defer {deferred_event} until the read VIO is re-enabled', 'END_STREAM must arrive while the producer is throttled.')
+        ts.Disk.traffic_out.Content += Testers.ContainsExpression(
+            f'rescheduled deferred {deferred_event}', 'The deferred END_STREAM must be rescheduled on re-enable.')
+    return ts
+
+
+# (path, frame that ends the response, event the stream defers)
+response_cases = (
+    ('data-end-stream', 'the last DATA frame', 'VC_EVENT_READ_COMPLETE'),
+    ('trailers', 'trailing HEADERS', 'VC_EVENT_EOS'),
+    # The GET request has already ended, so this empty frame closes the stream,
+    # and the EOS that initiating_close() sends is not held back by a disabled
+    # read VIO. Nothing is deferred; this guards that the path still completes.
+    ('empty-end-stream', 'an empty DATA frame', None),
+)
+for index, (path, frame, deferred_event) in enumerate(response_cases):
+    tr = Test.AddTestRun(f'HTTP/2 origin END_STREAM on {frame} -> HTTP/1.1 chunked client while throttled')
+    ts = make_ts(f'ts-h2o-{path}', deferred_event)
+    ts.Disk.remap_config.AddLine(f'map / https://127.0.0.1:{h2_origin_port}/')
+    if index == 0:
+        tr.Processes.Default.StartBefore(h2_origin)
+    tr.Processes.Default.StartBefore(ts)
+    tr.MakeCurlCommand(
+        f'-s --http1.1 --max-time 5 -o /dev/null -w "%{{size_download}} %{{http_code}}" http://127.0.0.1:{ts.Variables.port}/{path}',
+        ts=ts)
+    tr.Processes.Default.ReturnCode = 0
+    tr.Processes.Default.Streams.stdout = Testers.ContainsExpression(
+        '^60000 200$', 'The client must receive the whole body and the terminating chunk.')
+    tr.StillRunningAfter = h2_origin
diff --git a/tests/gold_tests/chunked_encoding/h2_end_stream_origin.py b/tests/gold_tests/chunked_encoding/h2_end_stream_origin.py
new file mode 100644
index 0000000000..35d1e900b2
--- /dev/null
+++ b/tests/gold_tests/chunked_encoding/h2_end_stream_origin.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python3
+"""An HTTP/2 origin that controls how, and when, each response ends its stream."""
+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import argparse
+import socket
+import ssl
+import sys
+import threading
+import time
+
+from h2.config import H2Configuration
+from h2.connection import H2Connection
+from h2.events import RequestReceived
+
+# The body has to fit in the default 65535-byte HTTP/2 windows so it is sent in
+# one write, and has to span several 16384-byte DATA frames, each well past the
+# 4096-byte water mark the test configures, so the throttle trips before the
+# frame that ends the stream is processed.
+BODY_SIZE = 60000
+# Long enough for ATS to start the response tunnel before the body arrives.
+HEADER_PAUSE_SECONDS = 0.5
+
+
+def queue_body(connection: H2Connection, stream_id: int, path: str) -> None:
+    """Queue a body without Content-Length and end the stream the way the path names.
+
+    /data-end-stream:  END_STREAM on the last DATA frame with payload.
+    /empty-end-stream: END_STREAM on a separate, empty DATA frame.
+    /trailers:         END_STREAM on a trailing HEADERS frame.
+    """
+    body = b"x" * BODY_SIZE
+    frame_size = connection.max_outbound_frame_size
+    for offset in range(0, len(body), frame_size):
+        last = offset + frame_size >= len(body)
+        connection.send_data(stream_id, body[offset:offset + frame_size], end_stream=last and path == "/data-end-stream")
+    if path == "/empty-end-stream":
+        connection.end_stream(stream_id)
+    elif path == "/trailers":
+        connection.send_headers(stream_id, [("x-trailer-check", "after-body")], end_stream=True)
+
+
+def serve_connection(context: ssl.SSLContext, plain_socket: socket.socket) -> None:
+    """Answer requests until the peer closes the connection."""
+    try:
+        tls_socket = context.wrap_socket(plain_socket, server_side=True)
+    except (ssl.SSLError, ConnectionError):
+        # Ignore readiness probes that never finish TLS.
+        plain_socket.close()
+        return
+    with tls_socket:
+        answer_requests(tls_socket)
+
+
+def answer_requests(tls_socket: ssl.SSLSocket) -> None:
+    """Respond to each request on an established HTTP/2 connection."""
+    connection = H2Connection(config=H2Configuration(client_side=False, header_encoding="utf-8"))
+    connection.initiate_connection()
+    tls_socket.sendall(connection.data_to_send())
+
+    while True:
+        try:
+            data = tls_socket.recv(65535)
+        except (ConnectionError, ssl.SSLError):
+            return
+        if not data:
+            return
+        for event in connection.receive_data(data):
+            if isinstance(event, RequestReceived):
+                path = dict(event.headers)[":path"]
+                print(f"request_received stream={event.stream_id} path={path}", flush=True)
+                connection.send_headers(event.stream_id, [(":status", "200"), ("content-type", "text/plain")])
+                tls_socket.sendall(connection.data_to_send())
+                time.sleep(HEADER_PAUSE_SECONDS)
+                try:
+                    queue_body(connection, event.stream_id, path)
+                except Exception as error:
+                    # Report on stdout, which the test checks, rather than dying quietly in this thread.
+                    print(f"queue_body_failed path={path} error={error!r}", flush=True)
+                    raise
+        # One write keeps the end of the stream right behind the body, so it
+        # arrives while the tunnel still has the producer throttled.
+        tls_socket.sendall(connection.data_to_send())
+
+
+def main() -> int:
+    """Serve HTTP/2 over TLS on the given port."""
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument("port", type=int)
+    parser.add_argument("certificate")
+    parser.add_argument("private_key")
+    args = parser.parse_args()
+
+    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
+    context.load_cert_chain(args.certificate, args.private_key)
+    context.set_alpn_protocols(["h2"])
+
+    with socket.create_server(("127.0.0.1", args.port)) as listener:
+        while True:
+            plain_socket, _ = listener.accept()
+            threading.Thread(target=serve_connection, args=(context, plain_socket), daemon=True).start()
+
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/tests/gold_tests/chunked_encoding/replays/chunked_h2_origin_flow_control.replay.yaml b/tests/gold_tests/chunked_encoding/replays/chunked_h2_origin_flow_control.replay.yaml
new file mode 100644
index 0000000000..2d558cad08
--- /dev/null
+++ b/tests/gold_tests/chunked_encoding/replays/chunked_h2_origin_flow_control.replay.yaml
@@ -0,0 +1,150 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+meta:
+  version: "1.0"
+
+# Regression test for the chunked-tunnel high-water throttle when the
+# producer is an outbound HTTP/2 stream.
+#
+# An HTTP/2 origin returns a body without Content-Length and an HTTP/1.1
+# client requests it, so ATS re-chunks the body for the client. With a small
+# default_buffer_water_mark the chunked output buffer crosses high_water
+# while the origin's DATA frames are still arriving, so the tunnel disables
+# the stream's read VIO. The origin's final DATA frame, carrying END_STREAM,
+# then lands while the read VIO is disabled. The stream has to deliver the
+# deferred final read event once the tunnel re-enables it, otherwise the
+# client never receives the terminating 0-size chunk. Whether END_STREAM
+# lands inside the throttle window depends on timing here;
+# chunked_flow_control.test.py pins it with a custom origin.
+
+autest:
+  description: 'HTTP/2 origin -> HTTP/1.1 chunked client END_STREAM while throttled'
+
+  dns:
+    name: 'dns-chunked-h2o-fc'
+
+  server:
+    name: 'server-chunked-h2o-fc'
+
+  client:
+    name: 'client-chunked-h2o-fc'
+
+  ats:
+    name: 'ts-chunked-h2o-fc'
+    process_config:
+      enable_tls: false
+      enable_cache: false
+
+    records_config:
+      proxy.config.diags.debug.enabled: 1
+      proxy.config.diags.debug.tags: 'http_tunnel|http2_stream'
+      # Keep every transaction on one thread so they share the origin session.
+      proxy.config.exec_thread.autoconfig.enabled: 0
+      proxy.config.exec_thread.limit: 1
+      # Small water_mark so the chunked output buffer crosses high_water
+      # while the origin's DATA frames are still being received.
+      proxy.config.http.default_buffer_water_mark: 4096
+      proxy.config.ssl.client.alpn_protocols: 'h2,http/1.1'
+      proxy.config.ssl.client.verify.server.policy: 'PERMISSIVE'
+      # Bound a stalled transaction so the failure shows as a truncated
+      # response rather than a hung test.
+      proxy.config.http.transaction_no_activity_timeout_out: 10
+
+    remap_config:
+      - from: "http://www.example.com/"
+        to: "https://backend.example.com:{SERVER_HTTPS_PORT}/"
+
+    log_validation:
+      diags_log:
+        excludes:
+          - expression: 'HTTP/2 unknown case of'
+            description: 'A stream stalled on a dropped END_STREAM must not linger.'
+
+    metric_checks:
+      - metric: proxy.process.http.tunnel.chunked_throttle
+        value: '[1-9][0-9]*'
+
+sessions:
+
+- protocol:
+    stack: http
+
+  transactions:
+
+  # The whole body fits in the initial stream window, so the origin sends
+  # every DATA frame back to back and the END_STREAM frame arrives while the
+  # tunnel still has the producer throttled.
+  - client-request:
+      method: GET
+      version: "1.1"
+      url: /h2o-rechunk
+      headers:
+        fields:
+        - [ Host, www.example.com ]
+        - [ uuid, h2o-rechunk-1 ]
+
+    proxy-request:
+      protocol:
+        stack: http2
+
+    server-response:
+      headers:
+        fields:
+        - [ ":status", 200 ]
+        - [ Content-Type, text/plain ]
+      content:
+        size: 60000
+
+    proxy-response:
+      status: 200
+      headers:
+        fields:
+        - [ "Transfer-Encoding", { value: "chunked", as: equal } ]
+      content:
+        size: { value: 60000, as: equal }
+
+  # A body several times the stream window, so the throttle and WINDOW_UPDATE
+  # cycles interleave with the final DATA frame.
+  - client-request:
+      delay: 100ms
+      method: GET
+      version: "1.1"
+      url: /h2o-rechunk-2
+      headers:
+        fields:
+        - [ Host, www.example.com ]
+        - [ uuid, h2o-rechunk-2 ]
+
+    proxy-request:
+      protocol:
+        stack: http2
+
+    server-response:
+      headers:
+        fields:
+        - [ ":status", 200 ]
+        - [ Content-Type, text/plain ]
+      content:
+        size: 524288
+
+    proxy-response:
+      status: 200
+      headers:
+        fields:
+        - [ "Transfer-Encoding", { value: "chunked", as: equal } ]
+      content:
+        size: { value: 524288, as: equal }