Copilot commented on code in PR #13801:
URL: https://github.com/apache/trafficserver/pull/13801#discussion_r4230447707


##########
tests/gold_tests/parent_proxy/bypass_parent.test.py:
##########
@@ -0,0 +1,80 @@
+'''
+Verify proxy.config.http.bypass_parent bypasses parent selection.
+'''
+#  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.
+
+Test.Summary = '''
+Verify proxy.config.http.bypass_parent bypasses parent.config, next-hop
+strategies, plugin-set parents, and CONNECT parenting, and yields to
+no_dns_just_forward_to_parent.
+'''
+
+Test.ATSReplayTest(replay_file='replays/bypass_parent.replay.yaml')
+Test.ATSReplayTest(replay_file='replays/bypass_parent_no_dns.replay.yaml')
+Test.ATSReplayTest(replay_file='replays/bypass_parent_plugin_parent.replay.yaml')
+Test.ATSReplayTest(replay_file='replays/bypass_parent_cache.replay.yaml')
+
+
+class BypassParentConnectTest:
+    '''CONNECT needs an outbound ip_allow rule for loopback, which 
ATSReplayTest cannot add.'''
+
+    replay_file = 'replays/bypass_parent_connect.replay.yaml'
+
+    def __init__(self):
+        self._server = Test.MakeVerifierServerProcess('server-connect', 
self.replay_file)
+        self._dns = Test.MakeDNServer('dns-connect', default='127.0.0.1')
+        self._server.Streams.stdout += Testers.ExcludesExpression(
+            'uuid: connect-', 'No CONNECT request reaches the server or the 
dead parent')
+        self._setup_ts()
+
+    def _setup_ts(self):
+        self._ts = Test.MakeATSProcess('ts-connect', enable_cache=False)
+        self._ts.Disk.records_config.update(
+            {
+                'proxy.config.diags.debug.enabled': 1,
+                'proxy.config.diags.debug.tags': 'http_trans|parent_select',
+                'proxy.config.dns.nameservers': 
f'127.0.0.1:{self._dns.Variables.Port}',
+                'proxy.config.dns.resolv_conf': 'NULL',
+                'proxy.config.http.connect_ports': 
f'{self._server.Variables.http_port}',

Review Comment:
   The CONNECT request in the replay targets port 80 
(`connect-direct.test:80`), but `connect_ports` is set to the verifier server’s 
port. If `connect_ports` enforcement happens on the pre-remap CONNECT target 
port (80), this test can fail depending on implementation details. Consider 
allowing both ports (e.g., include `80` and the verifier port), or explicitly 
align `connect_ports` with the port that ATS validates for remapped CONNECT.



##########
tests/gold_tests/parent_proxy/bypass_parent.test.py:
##########
@@ -0,0 +1,80 @@
+'''
+Verify proxy.config.http.bypass_parent bypasses parent selection.
+'''
+#  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.
+
+Test.Summary = '''
+Verify proxy.config.http.bypass_parent bypasses parent.config, next-hop
+strategies, plugin-set parents, and CONNECT parenting, and yields to
+no_dns_just_forward_to_parent.
+'''
+
+Test.ATSReplayTest(replay_file='replays/bypass_parent.replay.yaml')
+Test.ATSReplayTest(replay_file='replays/bypass_parent_no_dns.replay.yaml')
+Test.ATSReplayTest(replay_file='replays/bypass_parent_plugin_parent.replay.yaml')
+Test.ATSReplayTest(replay_file='replays/bypass_parent_cache.replay.yaml')
+
+
+class BypassParentConnectTest:
+    '''CONNECT needs an outbound ip_allow rule for loopback, which 
ATSReplayTest cannot add.'''
+
+    replay_file = 'replays/bypass_parent_connect.replay.yaml'
+
+    def __init__(self):
+        self._server = Test.MakeVerifierServerProcess('server-connect', 
self.replay_file)
+        self._dns = Test.MakeDNServer('dns-connect', default='127.0.0.1')
+        self._server.Streams.stdout += Testers.ExcludesExpression(
+            'uuid: connect-', 'No CONNECT request reaches the server or the 
dead parent')
+        self._setup_ts()
+
+    def _setup_ts(self):
+        self._ts = Test.MakeATSProcess('ts-connect', enable_cache=False)
+        self._ts.Disk.records_config.update(
+            {
+                'proxy.config.diags.debug.enabled': 1,
+                'proxy.config.diags.debug.tags': 'http_trans|parent_select',
+                'proxy.config.dns.nameservers': 
f'127.0.0.1:{self._dns.Variables.Port}',
+                'proxy.config.dns.resolv_conf': 'NULL',
+                'proxy.config.http.connect_ports': 
f'{self._server.Variables.http_port}',
+                'proxy.config.http.parent_proxy.self_detect': 0,
+                'proxy.config.http.uncacheable_requests_bypass_parent': 0,
+                'proxy.config.http.parent_proxy.total_connect_attempts': 1,
+                'proxy.config.http.parent_proxy.per_parent_connect_attempts': 
1,
+            })
+        self._ts.Disk.parent_config.AddLine('dest_domain=. 
parent="127.0.0.1:1|1" go_direct=false parent_is_proxy=true')
+        # Remap to a hostname: a 127.0.0.1 target would bypass the parent on 
its own as a localhost request.
+        server_port = self._server.Variables.http_port
+        self._ts.Disk.remap_config.AddLines(
+            [
+                f'map http://connect-direct.test:80/ 
http://origin.test:{server_port}/ '
+                '@plugin=conf_remap.so 
@pparam=proxy.config.http.bypass_parent=1',
+                f'map http://connect-parent.test:80/ 
http://origin.test:{server_port}/',
+            ])
+        self._ts.addPrivateConnectAllowYaml()
+
+    def run(self):
+        tr = Test.AddTestRun('bypass_parent bypasses the parent for CONNECT 
per remap rule')
+        tr.AddVerifierClientProcess('client-connect', self.replay_file, 
http_ports=[self._ts.Variables.port])
+        tr.Processes.Default.StartBefore(self._dns)
+        tr.Processes.Default.StartBefore(self._server)
+        tr.Processes.Default.StartBefore(self._ts)
+        tr.StillRunningAfter = self._dns
+        tr.StillRunningAfter = self._server
+        tr.StillRunningAfter = self._ts

Review Comment:
   These sequential assignments overwrite each other, so only the last one 
takes effect. If you intended to keep multiple processes alive, set 
`StillRunningAfter` once to the correct structure supported by the harness 
(e.g., a list/tuple), or remove the redundant lines if only `self._ts` is 
required.



##########
src/proxy/http/HttpTransact.cc:
##########
@@ -696,7 +696,21 @@ find_server_and_update_current_info(HttpTransact::State *s)
 {
   auto host{s->hdr_info.client_request.host_get()};
 
-  if (is_localhost(host)) {
+  // bypass_parent skips parent selection unless no_dns_just_forward_to_parent 
makes
+  // the parent responsible for reaching the origin.
+  bool bypass_parent = s->txn_conf->bypass_parent;
+  if (bypass_parent && s->txn_conf->no_dns_forward_to_parent) {
+    SiteThrottledWarning("proxy.config.http.bypass_parent is enabled, but "
+                         "proxy.config.http.no_dns_just_forward_to_parent 
prevents direct origin DNS; continuing with parent "
+                         "selection.");
+    bypass_parent = false;
+  }
+
+  if (bypass_parent) {
+    TxnDbg(dbg_ctl_http_trans, "bypassing parent selection due to 
proxy.config.http.bypass_parent (prior result %s)",
+           ParentResultStr[static_cast<int>(s->parent_result.result)]);
+    s->parent_result.result = ParentResultType::DIRECT;
+  } else if (is_localhost(host)) {

Review Comment:
   Forcing `s->parent_result.result` to `DIRECT` without clearing any other 
`parent_result` fields can leave stale parent/next-hop data from earlier 
selection (including plugin-set values) attached to the transaction state. If 
later code paths read other `parent_result` members (e.g., hostname/port/flags) 
without strictly gating on `result`, this can cause inconsistent behavior or 
misleading logging/metrics. Recommend explicitly resetting/clearing the 
remaining `parent_result` state when switching to `DIRECT` to keep the state 
self-consistent.



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