Skip to content

Improve signal handling and process cleanup in canary-download#4

Open
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/fix-canary-zombie-process-N97Yg
Open

Improve signal handling and process cleanup in canary-download#4
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/fix-canary-zombie-process-N97Yg

Conversation

@assisted-by-ai
Copy link
Copy Markdown
Contributor

Summary

This change improves the robustness of the canary-download script by implementing proper signal handling and ensuring child processes are cleaned up correctly in all error scenarios.

Key Changes

  • Added global _signify_process variable to track the signify subprocess
  • Enhanced canary_download_signal_handler() to properly terminate the signify process when a signal is received, preventing orphaned processes
  • Added process.wait() calls after process.kill() in timeout and exception handlers to ensure processes are fully reaped before exit
  • Declared _signify_process as global in the main function to allow the signal handler to access and clean up the subprocess

Implementation Details

The changes ensure that:

  1. When the script receives a signal (SIGTERM, SIGINT, etc.), it actively kills the signify subprocess and waits for it to terminate before exiting
  2. In timeout scenarios, the process is killed and waited for, preventing zombie processes
  3. In exception scenarios, the same cleanup procedure is followed
  4. All process termination is wrapped in try-except blocks to handle edge cases gracefully (e.g., process already terminated)

This prevents resource leaks and ensures clean shutdown in all code paths.

https://claude.ai/code/session_012TwkQYwRUwxpuNFPUdsZfd

process.kill() was called without process.wait() in both the
TimeoutExpired and BaseException exception handlers, leaving the
signify-openbsd child as a zombie. Also clean up the subprocess in the
SIGTERM/SIGINT signal handler so it is reaped when the outer timeout
command terminates canary-download.

https://claude.ai/code/session_012TwkQYwRUwxpuNFPUdsZfd
@ArrayBolt3
Copy link
Copy Markdown
Contributor

Accepted with tweaks in ArrayBolt3@5217b86, however this does not actually prevent canary from becoming a zombie process for some reason. (I suspect something that canary calls is exiting while canary is sleeping or otherwise doing something else, resulting in the zombie state. That zombie state eventually clears itself if you give it enough time.)

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.

3 participants