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


##########
tests/uranium_tests/h2/clients/h2_closed_stream_window_drain.py:
##########
@@ -0,0 +1,306 @@
+#!/usr/bin/env python3
+#  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.
+'''
+HTTP/2 client that floods a closed stream with DATA and then verifies the
+connection is still usable.
+'''
+
+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
+
+SETTINGS_MAX_FRAME_SIZE = 0x5
+
+# RFC 9113 section 6.5.2: the default SETTINGS_MAX_FRAME_SIZE, used until the
+# peer advertises its own.
+DEFAULT_MAX_FRAME_SIZE = 16384
+
+# RFC 9113 section 6.9.2: the connection window always starts at 65535;
+# SETTINGS_INITIAL_WINDOW_SIZE only applies to stream windows.
+INITIAL_WINDOW_SIZE = 65535
+
+# Send enough DATA to the closed stream to consume the initial connection
+# window twice over. A client that honors the connection-level flow-control
+# window can only do this if the peer credits the discarded bytes back with
+# connection-level WINDOW_UPDATE frames. Stream-level windows are not tracked:
+# the stream is closed, and ATS does not consult its window when discarding.
+CLOSED_STREAM_DATA_TOTAL = 2 * INITIAL_WINDOW_SIZE
+PROBE_BODY = b'p' * 1024
+
+# How long to wait for a WINDOW_UPDATE before concluding the connection window
+# has been drained for good.
+WINDOW_UPDATE_TIMEOUT_SECONDS = 3
+
+Frame = Tuple[int, int, int, bytes]
+
+
+class WindowDrained(Exception):
+    """Raised when the peer never replenishes the connection window."""
+
+
+class Http2Client:
+    """A minimal HTTP/2 client that tracks the connection send window."""
+
+    def __init__(self, port: int) -> None:
+        self._sock = self._make_socket(port)
+        self._encoder = hpack.Encoder()
+        self._decoder = hpack.Decoder()
+        self._send_window = INITIAL_WINDOW_SIZE
+        self._max_frame_size = DEFAULT_MAX_FRAME_SIZE
+        self._window_update_count = 0
+        self._window_update_total = 0
+        self._rst_stream_count: Dict[int, int] = {}
+        self._response_status: Dict[int, Optional[str]] = {}
+        self._response_done: Dict[int, bool] = {}
+
+    @staticmethod
+    def _make_socket(port: int) -> ssl.SSLSocket:
+        socket.setdefaulttimeout(10)
+        ctx = ssl.create_default_context()
+        ctx.check_hostname = False
+        ctx.verify_mode = ssl.CERT_NONE
+        ctx.set_alpn_protocols(['h2'])
+
+        raw_socket = socket.create_connection(('127.0.0.1', port))
+        tls_socket = ctx.wrap_socket(raw_socket, server_hostname='localhost')

Review Comment:
   Fixed in 42941fb0a9: the client no longer sets the process-wide default 
timeout. It passes `timeout=10` when it creates the connection instead.



-- 
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