-
Notifications
You must be signed in to change notification settings - Fork 847
Add ERR_TUN_ACTIVE_TIMEOUT squid code for tunnel timeouts #12786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bryancall
wants to merge
2
commits into
apache:master
Choose a base branch
from
bryancall:add-tunnel-timeout-squid-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| ''' | ||
| Verify that tunnel active timeout produces ERR_TUN_ACTIVE_TIMEOUT squid code. | ||
| ''' | ||
| # 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 os | ||
| import sys | ||
|
|
||
| Test.Summary = ''' | ||
| Verify that tunnel active timeout produces ERR_TUN_ACTIVE_TIMEOUT squid code. | ||
| ''' | ||
|
|
||
| ts = Test.MakeATSProcess("ts", enable_tls=True) | ||
| server = Test.MakeOriginServer("server", ssl=True) | ||
|
|
||
| # Simple response from origin | ||
| request_header = {"headers": "GET / HTTP/1.1\r\nHost: server\r\n\r\n", "timestamp": "1234", "body": ""} | ||
| response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1234", "body": "hello"} | ||
| server.addResponse("sessionlog.json", request_header, response_header) | ||
|
|
||
| ts.addDefaultSSLFiles() | ||
|
|
||
| ts.Disk.ssl_multicert_config.AddLine('dest_ip=* ssl_cert_name=server.pem ssl_key_name=server.key') | ||
|
|
||
| ts.Disk.records_config.update( | ||
| { | ||
| 'proxy.config.diags.debug.enabled': 1, | ||
| 'proxy.config.diags.debug.tags': 'http|ssl|tunnel', | ||
| 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, | ||
| 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, | ||
| 'proxy.config.ssl.client.verify.server.policy': 'PERMISSIVE', | ||
| 'proxy.config.http.connect_ports': f'{server.Variables.SSL_Port}', | ||
| # Set a short active timeout for tunnels (2 seconds) | ||
| 'proxy.config.http.transaction_active_timeout_in': 2, | ||
| # Force log flush every second for test reliability | ||
| 'proxy.config.log.max_secs_per_buffer': 1, | ||
| }) | ||
|
|
||
| ts.Disk.remap_config.AddLine(f'map / https://127.0.0.1:{server.Variables.SSL_Port}') | ||
|
|
||
| # Configure custom log format to capture squid code | ||
| ts.Disk.logging_yaml.AddLines( | ||
| ''' | ||
| logging: | ||
| formats: | ||
| - name: custom | ||
| format: '%<crc> %<pssc> %<cqhm>' | ||
| logs: | ||
| - filename: squid.log | ||
| format: custom | ||
| '''.split("\n")) | ||
|
|
||
| # Test: Perform a CONNECT request that will time out | ||
| tr = Test.AddTestRun("Tunnel active timeout test") | ||
| tr.Processes.Default.StartBefore(server) | ||
| tr.Processes.Default.StartBefore(ts) | ||
|
|
||
| # Use the tunnel_timeout_client.py script to establish a CONNECT tunnel and then | ||
| # just hold the connection until ATS times it out | ||
| tr.Setup.Copy('tunnel_timeout_client.py') | ||
|
|
||
| # Connect, establish tunnel, then sleep to trigger active timeout | ||
| tr.Processes.Default.Command = ( | ||
| f'{sys.executable} tunnel_timeout_client.py 127.0.0.1 {ts.Variables.port} ' | ||
| f'127.0.0.1 {server.Variables.SSL_Port} 5') | ||
| # The connection will be closed by ATS due to timeout | ||
| tr.Processes.Default.ReturnCode = 0 | ||
| tr.StillRunningAfter = ts | ||
|
|
||
| # Wait for the access log to be written | ||
| tr = Test.AddTestRun("Wait for the access log to write out") | ||
| tr.DelayStart = 3 | ||
| tr.StillRunningAfter = ts | ||
| tr.Processes.Default.Command = 'echo "waiting for log flush"' | ||
| tr.Processes.Default.ReturnCode = 0 | ||
|
|
||
| # Verify the squid code in the access log | ||
| ts.Disk.File(os.path.join(ts.Variables.LOGDIR, 'squid.log')).Content = Testers.ContainsExpression( | ||
| 'ERR_TUN_ACTIVE_TIMEOUT.*CONNECT', 'Verify the tunnel timeout squid code is logged') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #!/usr/bin/env python3 | ||
| ''' | ||
| A simple client that establishes a CONNECT tunnel and then holds the connection | ||
| idle to trigger an active timeout. | ||
| ''' | ||
| # 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(): | ||
| if len(sys.argv) < 6: | ||
| print(f"Usage: {sys.argv[0]} proxy_host proxy_port target_host target_port sleep_seconds") | ||
| sys.exit(1) | ||
|
|
||
| proxy_host = sys.argv[1] | ||
| proxy_port = int(sys.argv[2]) | ||
| target_host = sys.argv[3] | ||
| target_port = int(sys.argv[4]) | ||
| sleep_seconds = int(sys.argv[5]) | ||
|
|
||
| # Connect to the proxy | ||
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| sock.settimeout(10) | ||
|
|
||
| try: | ||
| sock.connect((proxy_host, proxy_port)) | ||
| print(f"Connected to proxy {proxy_host}:{proxy_port}") | ||
|
|
||
| # Send CONNECT request | ||
| connect_request = f"CONNECT {target_host}:{target_port} HTTP/1.1\r\nHost: {target_host}:{target_port}\r\n\r\n" | ||
| sock.sendall(connect_request.encode()) | ||
| print(f"Sent CONNECT request for {target_host}:{target_port}") | ||
|
|
||
| # Read the response | ||
| response = b"" | ||
| while b"\r\n\r\n" not in response: | ||
| data = sock.recv(1024) | ||
| if not data: | ||
| break | ||
| response += data | ||
|
|
||
| response_str = response.decode() | ||
| print(f"Received response: {response_str.strip()}") | ||
|
|
||
| if "200" not in response_str: | ||
| print(f"CONNECT failed: {response_str}") | ||
| sock.close() | ||
| sys.exit(1) | ||
|
|
||
| print(f"Tunnel established, sleeping for {sleep_seconds} seconds to trigger active timeout...") | ||
|
|
||
| # Now hold the connection idle until the active timeout fires | ||
| # Use a longer socket timeout so we can detect when ATS closes the connection | ||
| sock.settimeout(sleep_seconds + 5) | ||
|
|
||
| try: | ||
| # Wait for data or connection close | ||
| data = sock.recv(1024) | ||
| if not data: | ||
| print("Connection closed by server (timeout)") | ||
| else: | ||
| print(f"Received data: {data}") | ||
| except socket.timeout: | ||
| print("Socket timeout waiting for server") | ||
| except Exception as e: | ||
| print(f"Exception: {e}") | ||
|
|
||
| except socket.timeout: | ||
| print("Socket timeout during connect/handshake") | ||
| except Exception as e: | ||
| print(f"Error: {e}") | ||
| finally: | ||
| sock.close() | ||
|
|
||
| print("Done") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instance of context-manager class socket is closed in a finally block. Consider using 'with' statement.