From 06e93eae6081a08b2185fed66166f7d5e3a028ac Mon Sep 17 00:00:00 2001 From: 9640-Akhil Date: Wed, 27 May 2026 11:42:20 +0000 Subject: [PATCH 1/2] Fix Cuttlefish helper process leak on unresponsive ADB teardown The teardown routine bypasses the graceful 'stop_cvd' command when Cuttlefish freezes, hangs, or when the ADB connection goes offline, proceeding to force-kill only 'crosvm' and 'run_cvd'. This leaks helper processes like 'tombstone_receiver' and 'socket_vsock_proxy', leaving TCP ports bound indefinitely and causing subsequent boot attempts to fail with 'Address already in use' errors. This change ensures 'stop_cvd' is always attempted gracefully and force-kills all remaining CVD helper processes in the fallback path to guarantee clean port release. --- .../_internal/platforms/android/adb.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/clusterfuzz/_internal/platforms/android/adb.py b/src/clusterfuzz/_internal/platforms/android/adb.py index 47c59b31c72..5a904467122 100755 --- a/src/clusterfuzz/_internal/platforms/android/adb.py +++ b/src/clusterfuzz/_internal/platforms/android/adb.py @@ -54,6 +54,10 @@ LAUNCH_CVD_TIMEOUT = 2700 CMD_KILL_CROSVM = 'pkill crosvm' CMD_KILL_RUN_CVD = 'pkill run_cvd' +CMD_KILL_TOMBSTONE_RECEIVER = 'pkill tombstone_receiver' +CMD_KILL_SOCKET_VSOCK_PROXY = 'pkill socket_vsock_proxy' +CMD_KILL_LOGCAT_RECEIVER = 'pkill logcat_receiver' +CMD_KILL_MODEM_SIMULATOR = 'pkill modem_simulator' # Output patterns to parse "lsusb" output. LSUSB_BUS_RE = re.compile(r'Bus\s+(\d+)\s+Device\s+(\d+):.*') @@ -445,15 +449,36 @@ def stop_cuttlefish_device(): stop_cvd_cmd = os.path.join(cvd_bin_dir, 'stop_cvd') logs.info('stop_cvd_cmd: %s' % str(stop_cvd_cmd)) - if get_device_state() == 'device': + # Attempt a graceful shutdown. + try: execute_command( stop_cvd_cmd, timeout=RECOVERY_CMD_TIMEOUT, on_cuttlefish_host=True) time.sleep(STOP_CVD_WAIT) + except Exception as e: + logs.warning('Graceful stop_cvd failed or timed out: %s' % str(e)) + # Forcefully kill crosvm, run_cvd and all CVD helper processes to prevent + # port leaks. execute_command( CMD_KILL_CROSVM, timeout=RECOVERY_CMD_TIMEOUT, on_cuttlefish_host=True) execute_command( CMD_KILL_RUN_CVD, timeout=RECOVERY_CMD_TIMEOUT, on_cuttlefish_host=True) + execute_command( + CMD_KILL_TOMBSTONE_RECEIVER, + timeout=RECOVERY_CMD_TIMEOUT, + on_cuttlefish_host=True) + execute_command( + CMD_KILL_SOCKET_VSOCK_PROXY, + timeout=RECOVERY_CMD_TIMEOUT, + on_cuttlefish_host=True) + execute_command( + CMD_KILL_LOGCAT_RECEIVER, + timeout=RECOVERY_CMD_TIMEOUT, + on_cuttlefish_host=True) + execute_command( + CMD_KILL_MODEM_SIMULATOR, + timeout=RECOVERY_CMD_TIMEOUT, + on_cuttlefish_host=True) def restart_cuttlefish_device(): From 62d8bcfa332faf25ed6a3ea9a7c5a07c19df1d8d Mon Sep 17 00:00:00 2001 From: 9640-Akhil Date: Thu, 28 May 2026 11:34:33 +0000 Subject: [PATCH 2/2] Simplify Cuttlefish teardown Use a single directory-targeted pkill command instead of maintaining a hardcoded list of individual helper processes and running multiple separate SSH commands. --- .../_internal/platforms/android/adb.py | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/clusterfuzz/_internal/platforms/android/adb.py b/src/clusterfuzz/_internal/platforms/android/adb.py index 5a904467122..f6a80b9a6b0 100755 --- a/src/clusterfuzz/_internal/platforms/android/adb.py +++ b/src/clusterfuzz/_internal/platforms/android/adb.py @@ -53,11 +53,6 @@ STOP_CVD_WAIT = 20 LAUNCH_CVD_TIMEOUT = 2700 CMD_KILL_CROSVM = 'pkill crosvm' -CMD_KILL_RUN_CVD = 'pkill run_cvd' -CMD_KILL_TOMBSTONE_RECEIVER = 'pkill tombstone_receiver' -CMD_KILL_SOCKET_VSOCK_PROXY = 'pkill socket_vsock_proxy' -CMD_KILL_LOGCAT_RECEIVER = 'pkill logcat_receiver' -CMD_KILL_MODEM_SIMULATOR = 'pkill modem_simulator' # Output patterns to parse "lsusb" output. LSUSB_BUS_RE = re.compile(r'Bus\s+(\d+)\s+Device\s+(\d+):.*') @@ -457,28 +452,13 @@ def stop_cuttlefish_device(): except Exception as e: logs.warning('Graceful stop_cvd failed or timed out: %s' % str(e)) - # Forcefully kill crosvm, run_cvd and all CVD helper processes to prevent - # port leaks. + # Forcefully kill crosvm and all CVD helper processes to prevent port leaks. execute_command( CMD_KILL_CROSVM, timeout=RECOVERY_CMD_TIMEOUT, on_cuttlefish_host=True) + + kill_helpers_cmd = f'pkill -f "{cvd_bin_dir}/"' execute_command( - CMD_KILL_RUN_CVD, timeout=RECOVERY_CMD_TIMEOUT, on_cuttlefish_host=True) - execute_command( - CMD_KILL_TOMBSTONE_RECEIVER, - timeout=RECOVERY_CMD_TIMEOUT, - on_cuttlefish_host=True) - execute_command( - CMD_KILL_SOCKET_VSOCK_PROXY, - timeout=RECOVERY_CMD_TIMEOUT, - on_cuttlefish_host=True) - execute_command( - CMD_KILL_LOGCAT_RECEIVER, - timeout=RECOVERY_CMD_TIMEOUT, - on_cuttlefish_host=True) - execute_command( - CMD_KILL_MODEM_SIMULATOR, - timeout=RECOVERY_CMD_TIMEOUT, - on_cuttlefish_host=True) + kill_helpers_cmd, timeout=RECOVERY_CMD_TIMEOUT, on_cuttlefish_host=True) def restart_cuttlefish_device():