Copilot commented on code in PR #13574:
URL: https://github.com/apache/trafficserver/pull/13574#discussion_r3845361919
##########
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) > 0) ?
TSVIONBytesGet(input_vio) : INT64_MAX;
Review Comment:
`TSVIONBytesGet(input_vio)` can legitimately be `0` (e.g., no body). In
`request_hdr_mode` this currently falls back to `INT64_MAX`, which makes the
output VIO expect an unbounded write and can prevent the transform from ever
completing for zero-length bodies. Use `>= 0` (or explicitly handle `0`) so
zero-length requests write `0` bytes instead of `INT64_MAX`.
##########
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 pass even when the client did *not* receive an HTTP
response, because `partial_post_client.py` prints a line containing `HTTP/1.1`
on connection reset. This makes the test a false-positive for the “received
response” claim. Either (a) assert on a stricter pattern like `^HTTP/1\.1 \d+`
from the actual response line, or (b) change the client’s reset message so it
doesn’t contain `HTTP/1.1` and update the assertion accordingly (or accept
either “response line” *or* “connection reset” explicitly).
##########
src/proxy/http/HttpSM.cc:
##########
@@ -2145,6 +2145,16 @@ HttpSM::state_read_server_response_header(int event,
void *data)
// If there is a post body in transit, give up on it
if (tunnel.is_tunnel_alive()) {
tunnel.abort_tunnel();
+ // abort_tunnel() cancels I/O but does not close VCs or clean up
+ // vc_table entries. When a request transform is active the
+ // post_transform_info entry still references the TransformVConnection
+ // with in_tunnel=true, which causes cleanup_entry() to skip
+ // do_io_close() — leaking the VC. Close it explicitly here.
+ if (post_transform_info.entry != nullptr) {
+ post_transform_info.vc->do_io_close();
+ vc_table.cleanup_entry(post_transform_info.entry);
Review Comment:
The new block intentionally leaves `post_transform_info.vc` non-null after
closing it (per the PR description, to signal to `transform_cleanup()` that the
chain was already closed). That ownership/signaling nuance isn’t obvious at the
call site. Add a short clarifying comment here explaining why `vc` is *not*
nulled to prevent future refactors from “cleaning it up” and reintroducing
leaks or double-closes.
##########
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)')
Review Comment:
Printing `HTTP/1.1 ...` on the reset path blurs the meaning of the output
(it looks like a real status line) and can cause tests to pass without a real
response (see `ContainsExpression('HTTP/1.1', ...)`). Consider changing this
message to not start with or include `HTTP/1.1`, and/or have the test
explicitly accept a “reset” message separately from a real HTTP status line.
--
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]