diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index 884e25bbd76..887eecbb317 100644 --- a/src/traffic_server/traffic_server.cc +++ b/src/traffic_server/traffic_server.cc @@ -174,6 +174,16 @@ static int poll_timeout = -1; // No value set. static int cmd_disable_freelist = 0; static bool signal_received[NSIG]; +/* +To be able to attach with a debugger to traffic_server running in an Au test case, temporarily add the +parameter block_for_debug=True to the call to Test.MakeATSProcess(). This means Au test will wait +effectively indefinitely (10 hours) for traffic_server to initialize itself. Run the modified Au test, +attach the debugger to the traffic_server process, set one or more breakpoints, set the variable +cmd_block to 0, then continue. On linux, the command 'ps -ef | fgrep -e --block' will help identify the +PID of the traffic_server process (second column of output). +*/ +static int cmd_block = 0; + // 1: the main thread delayed accepting, start accepting. // 0: delay accept, wait for cache initialization. // -1: cache is already initialized, don't delay. @@ -217,6 +227,7 @@ static ArgumentDescription argument_descriptions[] = { {"bind_stderr", '-', "Regular file to bind stderr to", "S512", &bind_stderr, "PROXY_BIND_STDERR", nullptr}, {"accept_mss", '-', "MSS for client connections", "I", &accept_mss, nullptr, nullptr}, {"poll_timeout", 't', "poll timeout in milliseconds", "I", &poll_timeout, nullptr, nullptr}, + {"block", '-', "block for debug attach", "T", &cmd_block, nullptr, nullptr}, HELP_ARGUMENT_DESCRIPTION(), VERSION_ARGUMENT_DESCRIPTION(), RUNROOT_ARGUMENT_DESCRIPTION(), @@ -1753,6 +1764,12 @@ main(int /* argc ATS_UNUSED */, const char **argv) command_index = find_cmd_index(command_string); command_valid = command_flag && command_index >= 0; + // Attach point when TS is blocked for debugging is in this loop. + // + while (cmd_block) { + sleep(1); + } + ink_freelist_init_ops(cmd_disable_freelist, cmd_disable_pfreelist); #if TS_HAS_TESTS diff --git a/tests/gold_tests/autest-site/trafficserver.test.ext b/tests/gold_tests/autest-site/trafficserver.test.ext index c679dc2db8b..502d65ef228 100755 --- a/tests/gold_tests/autest-site/trafficserver.test.ext +++ b/tests/gold_tests/autest-site/trafficserver.test.ext @@ -27,9 +27,11 @@ def make_id(s): # this forms is for the global process define - +# 'block_for_debug', if True, causes traffic_server to run with the --block option enabled, and effectively +# disables timeouts that could be triggered by running traffic_server under a debugger. def MakeATSProcess(obj, name, command='traffic_server', select_ports=True, - enable_tls=False, enable_cache=True, enable_quic=False): + enable_tls=False, enable_cache=True, enable_quic=False, + block_for_debug=False): ##################################### # common locations @@ -60,6 +62,14 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True, storage_dir = os.path.join(ts_dir, 'storage') cache_dir = os.path.join(ts_dir, 'cache') + if block_for_debug: + if command.startswith('traffic_server'): + command += ' --block' + elif command.startswith('traffic_manager'): + if '--tsArgs' not in command: + command += ' --tsArgs' + command += ' --block' + # create process p = obj.Processes.Process(name, command) #p_debug = obj.Processes.Process("port-debug", "ss --listen --tcp --process") @@ -341,6 +351,15 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True, else: p.ReturnCode = 0 + if block_for_debug: + p.Env['PROXY_BLOCK'] = '1' + # Cause traffic_server to wait effectviely indefinitely (10 hours) for the debugger to attach. + p.StartupTimeout = 10 * 60 * 60 + # Hitting breakpoints may cause long delays in traffic_server transaction processing, so make + # the timeout for test processes (that may interact with traffic_server) effectively forever + # (10 hours). + obj.Variables.Autest.Process.TimeOut = 10 * 60 * 60 + return p