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

asyncio_tools: add SIGHUP handling for terminal close termination #49

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

fsagbuya
Copy link
Contributor

@fsagbuya fsagbuya commented Nov 28, 2024

Description

Add SIGHUP signal handling to properly terminate processes upon terminal close. Affects processes that use SignalHandler.

Tested with: artiq_ctlmgr and artiq_session

Closes m-labs/artiq#2614

@sbourdeauducq sbourdeauducq merged commit aff9cbb into m-labs:master Dec 11, 2024
@sbourdeauducq
Copy link
Member

sbourdeauducq commented Dec 11, 2024

Tested with: artiq_ctlmgr

Did the test include checking that controllers are terminated cleanly? By ctlmgr?
Why are the controllers apparently not receiving SIGHUP themselves?

@sbourdeauducq
Copy link
Member

and artiq_session

artiq_session is not using this sipyco signal handler itself. But some of its child processes do. Assuming this PR did make a difference, I suppose these child processes did receive SIGHUP. Why the difference with the child processes started by ctlmgr?

@sbourdeauducq
Copy link
Member

Also, this breaks Windows. signal.SIGHUP is not even defined there.

@fsagbuya
Copy link
Contributor Author

Did the test include checking that controllers are terminated cleanly? By ctlmgr?

Yes. Showing from this strace log:

sudo strace -p 153249 -e signal
strace: Process 153249 attached
--- SIGHUP {si_signo=SIGHUP, si_code=SI_USER, si_pid=144910, si_uid=1000} ---
--- SIGCONT {si_signo=SIGCONT, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]})                 = -1 EINTR (Interrupted system call)
--- SIGHUP {si_signo=SIGHUP, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[]})                 = -1 EINTR (Interrupted system call)
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=153250, si_uid=1000, si_status=0, si_utime=14 /* 0.14 s */, si_stime=1 /* 0.01 s */} ---
rt_sigaction(SIGINT, {sa_handler=0x7ffff7951530, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, {sa_handler=0x7ffff7951530, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, 8) = 0
rt_sigaction(SIGTERM, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, {sa_handler=0x7ffff7951530, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, 8) = 0
rt_sigaction(SIGHUP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, {sa_handler=0x7ffff7951530, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, {sa_handler=0x7ffff7951530, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7ffff7560620}, 8) = 0
+++ exited with 120 +++

Why are the controllers apparently not receiving SIGHUP themselves?

Most likely because of the start_new_session=True in controllers

@fsagbuya
Copy link
Contributor Author

fsagbuya commented Dec 14, 2024

artiq_session is not using this sipyco signal handler itself. But some of its child processes do. Assuming this PR did make a difference, I suppose these child processes did receive SIGHUP. Why the difference with the child processes started by ctlmgr?

From another strace log, artiq_session's children (master, dashboard, ctlmgr) receive SIGHUP directly because they're created with Popen(). The controllers started by ctlmgr don't receive SIGHUP directly due to start_new_session=True, but they exit through ctlmgr's atexit handlers which now run when terminal closes with the new SIGHUP handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

closing Gnome terminal window with artiq_ctlmgr leaves controllers running in the background
2 participants