Copilot commented on code in PR #13574:
URL: https://github.com/apache/trafficserver/pull/13574#discussion_r3845127364
##########
tests/gold_tests/slow_post/quick_server.test.py:
##########
@@ -105,22 +116,30 @@ def run(self):
http_utils = os.path.join(tools_dir, 'http_utils.py')
tr.Setup.CopyAs(self._init_file, Test.RunDirectory)
tr.Setup.CopyAs(http_utils, Test.RunDirectory)
- tr.Setup.CopyAs(self._slow_post_client, Test.RunDirectory)
tr.Setup.CopyAs(self._quick_server, Test.RunDirectory)
- client_command = (f'{sys.executable} {self._slow_post_client} '
- '127.0.0.1 '
- f'{self._ts.Variables.port} ')
- if not self._should_abort_request:
- client_command += '--finish-request '
- p = tr.Processes.Default
- p.Command = client_command
- if self._should_abort_request or self._should_abort_response_headers:
- p.Streams.All += Testers.ExcludesExpression('HTTP/1.1 200 OK',
'Verify response was received')
+ if self._use_request_transform:
+ tr.Setup.CopyAs(self._partial_post_client, Test.RunDirectory)
+ p = tr.Processes.Default
+ p.Command = (f'{sys.executable} {self._partial_post_client} '
+ f'127.0.0.1 {self._ts.Variables.port}')
+ p.ReturnCode = 0
+ p.Streams.All += Testers.ContainsExpression('HTTP/1.1', 'Verify
client received an HTTP response')
Review Comment:
This assertion can produce false positives because the partial-post client
currently prints a line containing 'HTTP/1.1' even when it did not actually
receive any HTTP response bytes (e.g., on connection reset). To make this test
meaningful, tighten the match to the actual status line from the origin (e.g.,
'HTTP/1.1 200 OK') and/or ensure the client only prints 'HTTP/1.1 ...' when it
has received and parsed a real response line.
##########
tests/gold_tests/slow_post/partial_post_client.py:
##########
@@ -0,0 +1,77 @@
+#!/usr/bin/env python3
+"""Send a partial POST to trigger the abort_tunnel code path.
+
+Sends POST headers claiming a large Content-Length but only sends a small
+chunk of body data. When a request transform plugin is active, this causes
+ATS to call abort_tunnel() while the transform entry is still in the vc_table.
+"""
+
+# 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 socket
+import sys
+
+
+def main() -> int:
+ """Run the client."""
+ host = sys.argv[1] if len(sys.argv) > 1 else '127.0.0.1'
+ port = int(sys.argv[2]) if len(sys.argv) > 2 else 8080
+
+ request = (
+ 'POST / HTTP/1.1\r\n'
+ 'Host: quick.server.com\r\n'
+ 'Content-Type: application/octet-stream\r\n'
+ 'Content-Length: 100000\r\n'
+ '\r\n').encode()
+
+ partial_body = b'x' * 4096
+
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.settimeout(5)
+ try:
+ sock.connect((host, port))
+ sock.sendall(request + partial_body)
+ print(f'Sent POST headers (Content-Length: 100000) +
{len(partial_body)} bytes')
+
+ try:
+ response = sock.recv(4096)
+ except ConnectionError:
+ # ATS may reset the connection after responding since the POST
+ # body is incomplete. This is acceptable — the important thing
+ # is that ATS did not crash.
+ print('HTTP/1.1 connection reset (expected for partial POST)')
+ return 0
+ except socket.timeout:
+ print('ERROR: timeout waiting for response', file=sys.stderr)
+ return 1
+
+ if response:
+ first_line = response.split(b'\r\n')[0].decode(errors='replace')
+ print(first_line)
+ if first_line.startswith('HTTP/1.1'):
+ return 0
+ print('ERROR: unexpected response', file=sys.stderr)
+ return 1
+ else:
+ print('ERROR: connection closed with no response', file=sys.stderr)
+ return 1
Review Comment:
Returning success on `ConnectionError` (and printing a string containing
'HTTP/1.1') can mask cases where ATS resets the connection before sending any
response at all. If the intent is to validate that a response was produced,
treat a reset-before-response as failure (or attempt to read until at least the
response line is received), and avoid printing an 'HTTP/1.1' prefix unless it
came from the server response.
##########
tests/gold_tests/slow_post/partial_post_client.py:
##########
@@ -0,0 +1,77 @@
+#!/usr/bin/env python3
+"""Send a partial POST to trigger the abort_tunnel code path.
+
+Sends POST headers claiming a large Content-Length but only sends a small
+chunk of body data. When a request transform plugin is active, this causes
+ATS to call abort_tunnel() while the transform entry is still in the vc_table.
+"""
+
+# 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 socket
+import sys
+
+
+def main() -> int:
+ """Run the client."""
+ host = sys.argv[1] if len(sys.argv) > 1 else '127.0.0.1'
+ port = int(sys.argv[2]) if len(sys.argv) > 2 else 8080
+
+ request = (
+ 'POST / HTTP/1.1\r\n'
+ 'Host: quick.server.com\r\n'
+ 'Content-Type: application/octet-stream\r\n'
+ 'Content-Length: 100000\r\n'
Review Comment:
The PR description says the test uses `Content-Length: 10000000` and sends
small chunks slowly, but the new client currently uses `Content-Length: 100000`
and sends a single 4096-byte chunk. Please align either the PR description or
the test implementation so the documented reproduction scenario matches what
the test actually does.
##########
tests/tools/plugins/tunnel_transform.cc:
##########
@@ -99,7 +107,8 @@ handle_transform(TSCont contp, bool forward)
data->output_buffer = TSIOBufferCreate();
data->output_reader = TSIOBufferReaderAlloc(data->output_buffer);
Dbg(plugin_ctl, "\tWriting %" PRId64 " bytes on VConn",
TSVIONBytesGet(input_vio));
- data->output_vio = TSVConnWrite(output_conn, contp, data->output_reader,
INT64_MAX);
+ int64_t nbytes = request_hdr_mode ? TSVIONBytesGet(input_vio) :
INT64_MAX;
+ data->output_vio = TSVConnWrite(output_conn, contp, data->output_reader,
nbytes);
Review Comment:
In `request_hdr_mode`, using `TSVIONBytesGet(input_vio)` directly can break
the transform if that value is 0 (or otherwise not yet set to the intended
total) when the first write VIO is created, since `TSVConnWrite(..., 0)` will
complete immediately and may truncate forwarding. Consider guarding this by
falling back to `INT64_MAX` when the retrieved nbytes is not a positive, known
total.
--
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]