Skip to content
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

pandad: reset safety mode on exit #32103

Merged
merged 37 commits into from
Jan 22, 2025
Merged

pandad: reset safety mode on exit #32103

merged 37 commits into from
Jan 22, 2025

Conversation

adeebshihadeh
Copy link
Contributor

allows for restarting the device while onroad without faulting the car

selfdrive/boardd/boardd.cc Outdated Show resolved Hide resolved
@adeebshihadeh adeebshihadeh added this to the 0.9.7 milestone Apr 5, 2024
Copy link
Contributor

github-actions bot commented May 6, 2024

This PR has had no activity for 30 days. It will be automatically closed in 7 days if there is no activity.

@github-actions github-actions bot added the stale label May 6, 2024
Copy link
Contributor

This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes.

@github-actions github-actions bot closed this May 13, 2024
@adeebshihadeh adeebshihadeh reopened this May 13, 2024
@github-actions github-actions bot removed the stale label May 14, 2024
@adeebshihadeh adeebshihadeh marked this pull request as draft May 22, 2024 00:25
@sshane sshane force-pushed the boardd-no-fault branch from fce03c2 to 01b598e Compare May 30, 2024 09:11
@sshane sshane changed the title boardd: reset safety mode on exit pandad: reset safety mode on exit Jun 6, 2024
Comment on lines 66 to 77
# override manager's immediate SystemExit to allow pandad to exit gracefully
def signal_handler(signum, frame):
nonlocal do_exit
do_exit = True
cloudlog.warning(f"caught signal {signum}, exiting")

do_exit = False
signal.signal(signal.SIGTERM, signal_handler)

Copy link
Contributor

Choose a reason for hiding this comment

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

When creating a new Python process with multiprocessing.Process, it inherits the parent's signal handler. For manager, that is to cause a SystemExit immediately, which SIGKILLs pandad.cc before it has a chance to react to the SIGTERM and close the relay.

# SystemExit on sigterm
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(1))

sshane added 3 commits June 6, 2024 03:58
old-commit-hash: 5094960
old-commit-hash: 5f24167
old-commit-hash: 1664113
common/util.h Outdated Show resolved Hide resolved
@sshane sshane mentioned this pull request Jan 18, 2025
@sshane
Copy link
Contributor

sshane commented Jan 22, 2025

The time between the two pandad stop calls is anywhere between 1 and 2s, so this is already plenty of time to receive the signal and close the relay, no extra sleeps are needed at this time:

for p in managed_processes.values():
p.stop(block=False)
# ensure all are killed
for p in managed_processes.values():
p.stop(block=True)

@sshane sshane marked this pull request as ready for review January 22, 2025 02:30
@sshane sshane merged commit bb09fd0 into master Jan 22, 2025
15 of 16 checks passed
@sshane sshane deleted the boardd-no-fault branch January 22, 2025 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants