bneradt commented on code in PR #13641:
URL: https://github.com/apache/trafficserver/pull/13641#discussion_r4457612300


##########
src/proxy/http2/Http2ConnectionState.cc:
##########
@@ -149,6 +153,7 @@ Http2ConnectionState::rcv_data_frame(const Http2Frame 
&frame)
   // the recipient MUST respond with a stream error of type STREAM_CLOSED.
   if (stream->get_state() != Http2StreamState::HTTP2_STREAM_STATE_OPEN &&
       stream->get_state() != 
Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_LOCAL) {
+    this->credit_discarded_data(payload_length);

Review Comment:
   Agreed, these are the same bug. Every stream-level discard return in 
`rcv_data_frame()` now tops up the connection window: 
`payload_length_is_valid()`, the stream `local_rwnd < payload_length` 
flow-control error, `no writer`, and `Write mismatch`. I also added it to the 
`change_state()` failure branch. You're right that the branch is unreachable 
today, but the call costs nothing and keeps the function's discard paths 
uniform if the state checks above it change. The connection-error returns are 
still left alone.



##########
include/proxy/http2/Http2ConnectionState.h:
##########
@@ -130,6 +130,7 @@ class Http2ConnectionState : public Continuation
   void         release_stream();
   void         cleanup_streams();
   void         restart_receiving(Http2Stream *stream);
+  void         credit_discarded_data(uint32_t payload_length);

Review Comment:
   Done. It's now the private `_top_up_window_after_discard(uint32_t 
discarded_length)`. The name reflects the absolute top-up semantics, and the 
Doxygen comment says the length is only logged. I kept the parameter so the 
debug line still reports each frame's size; the test keys on it.



##########
src/proxy/http2/Http2ConnectionState.cc:
##########
@@ -126,6 +128,7 @@ Http2ConnectionState::rcv_data_frame(const Http2Frame 
&frame)
   if (stream == nullptr) {
     if (this->is_valid_streamid(id)) {
       // This error occurs fairly often, and is probably innocuous (SM 
initiates the shutdown)
+      this->credit_discarded_data(payload_length);

Review Comment:
   Fixed: the call now sits above that comment.



##########
tests/uranium_tests/h2/clients/h2_closed_stream_window_drain.py:
##########
@@ -0,0 +1,291 @@
+#!/usr/bin/env python3
+'''
+HTTP/2 client that floods a closed stream with DATA and then verifies the
+connection is still usable.
+'''
+#  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
+from typing import Dict, List, Optional, Tuple
+
+import hpack
+
+CONNECTION_PREFACE = b'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'
+
+FRAME_TYPE_DATA = 0
+FRAME_TYPE_HEADERS = 1
+FRAME_TYPE_RST_STREAM = 3
+FRAME_TYPE_SETTINGS = 4
+FRAME_TYPE_PING = 6
+FRAME_TYPE_GOAWAY = 7
+FRAME_TYPE_WINDOW_UPDATE = 8
+
+FLAG_ACK = 0x01
+FLAG_END_STREAM = 0x01
+FLAG_END_HEADERS = 0x04
+
+CONNECTION_STREAM_ID = 0
+CLOSED_STREAM_ID = 1
+PROBE_STREAM_ID = 3
+
+MAX_FRAME_SIZE = 16384

Review Comment:
   Fixed. The client now reads `SETTINGS_MAX_FRAME_SIZE` from ATS's SETTINGS 
frame and sizes its DATA frames from it. The connection window stays hardcoded 
at 65535 because RFC 9113 section 6.9.2 fixes it there; 
`SETTINGS_INITIAL_WINDOW_SIZE` only affects stream windows. The comment now 
says explicitly that only the connection-level window is honored, and that the 
stream window isn't tracked because ATS doesn't consult it on the discard path.



##########
tests/gold_tests/h2/http2_flow_control.test.py:
##########
@@ -383,6 +383,47 @@ def run(self) -> None:
             'ATS should log the expected SETTINGS_TIMEOUT connection error.')
 
 
+class Http2ClosedStreamFlowControlTest:
+    """Verify DATA to closed streams cannot drain the connection window."""
+
+    def run(self) -> None:
+        """Configure the test run."""
+        tr = Test.AddTestRun('Closed-stream DATA does not drain connection 
window')
+        server = tr.MakeHttpBinServer('server-closed-stream-window')
+        ts = tr.MakeATSProcess('ts-closed-stream-window', enable_tls=True, 
enable_cache=False)
+
+        ts.addDefaultSSLFiles()
+        ts.Setup.CopyAs('clients/h2_closed_stream_window_drain.py', 
Test.RunDirectory)
+        ts.Disk.records_config.update(
+            {
+                'proxy.config.diags.debug.enabled': 1,
+                'proxy.config.diags.debug.tags': 'http2',
+                'proxy.config.ssl.server.cert.path': f'{ts.Variables.SSLDir}',
+                'proxy.config.ssl.server.private_key.path': 
f'{ts.Variables.SSLDir}',
+            })
+        ts.Disk.remap_config.AddLine(f'map / 
http://127.0.0.1:{server.Variables.Port}')
+        ts.Disk.ssl_multicert_yaml.AddLines(
+            """
+ssl_multicert:
+  - dest_ip: "*"
+    ssl_cert_name: server.pem
+    ssl_key_name: server.key
+""".split("\n"))
+
+        tr.Processes.Default.StartBefore(server)
+        tr.Processes.Default.StartBefore(ts)
+        tr.Processes.Default.Command = f'{sys.executable} 
h2_closed_stream_window_drain.py {ts.Variables.ssl_port}'
+        tr.Processes.Default.ReturnCode = 0

Review Comment:
   Done. Since this PR was opened, the AuTest was converted to a Uranium test 
(`tests/uranium_tests/h2/test_http2_flow_control.py`). The client run now 
passes `timeout=20`, matching `test_dynamic_window_settings_cap` in that file.



##########
tests/gold_tests/h2/http2_flow_control.test.py:
##########
@@ -383,6 +383,47 @@ def run(self) -> None:
             'ATS should log the expected SETTINGS_TIMEOUT connection error.')
 
 
+class Http2ClosedStreamFlowControlTest:

Review Comment:
   Agreed that the outbound direction is the more interesting one. I'd like to 
cover it in a follow-up. Exercising it needs an HTTP/2 origin that keeps 
sending DATA after ATS has reset or closed the stream. The existing Proxy 
Verifier origin can't do that, so it means another bespoke server-side client, 
which is a bigger addition than this PR. I'm leaving this thread open to track 
it.



##########
src/proxy/http2/Http2ConnectionState.cc:
##########
@@ -149,6 +153,7 @@ Http2ConnectionState::rcv_data_frame(const Http2Frame 
&frame)
   // the recipient MUST respond with a stream error of type STREAM_CLOSED.
   if (stream->get_state() != Http2StreamState::HTTP2_STREAM_STATE_OPEN &&
       stream->get_state() != 
Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_LOCAL) {
+    this->credit_discarded_data(payload_length);
     return Http2Error(Http2ErrorClass::HTTP2_ERROR_CLASS_STREAM, 
Http2ErrorCode::HTTP2_ERROR_STREAM_CLOSED,

Review Comment:
   Fixed. Every stream-level discard return you listed now calls the top-up 
helper (renamed `_top_up_window_after_discard()`): `change_state()` failure, 
`payload_length_is_valid()`, the stream `local_rwnd` check, `no writer`, and 
`Write mismatch`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to