Skip to content

autopilot manager: fix auto_restart_autopilot() race condition #3474

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/services/ardupilot_manager/autopilot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,12 @@ def is_ardupilot_process(process: psutil.Process) -> bool:
"""Checks if given process is using a Ardupilot's firmware file, for any known platform."""
for platform in Platform:
firmware_path = self.firmware_manager.firmware_path(platform)
if str(firmware_path) in " ".join(process.cmdline()):
return True
try:
if str(firmware_path) in " ".join(process.cmdline()):
return True
except psutil.NoSuchProcess:
# process may have died before we could call cmdline()
pass
Comment on lines +502 to +507
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider broadening exception handling to include AccessDenied and ZombieProcess.

psutil.cmdline() may also raise AccessDenied or ZombieProcess, so including these in the exception handling will improve reliability.

Suggested implementation:

                try:
                    if str(firmware_path) in " ".join(process.cmdline()):
                        return True
                except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
                    # process may have died, become a zombie, or access was denied before we could call cmdline()
                    pass

If psutil.AccessDenied and psutil.ZombieProcess are not already imported in this file, ensure that import psutil is present at the top of the file. If only specific exceptions are imported, add these two to the import statement.

return False

return list(filter(is_ardupilot_process, psutil.process_iter()))
Expand Down
Loading