Add graceful shutdown support with signal context handling#35
Add graceful shutdown support with signal context handling#35yiftach-armis merged 5 commits intomainfrom
Conversation
Test Coverage Reporttotal: (statements) 77.1% Coverage by function |
4e0c4d1 to
bdf617f
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds graceful shutdown support to allow users to interrupt long-running scans with Ctrl+C (SIGINT) or SIGTERM signals. The implementation ensures proper cleanup of resources and provides clear user feedback when scans are cancelled.
Changes:
- Introduced signal-aware context handling utility (
NewSignalContext()) - Updated scan commands to use signal contexts with proper cancellation handling
- Refactored image scanner cleanup to use defer pattern for guaranteed resource cleanup
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/context.go | New utility function to create contexts that cancel on SIGINT/SIGTERM |
| internal/cmd/context_test.go | Unit tests for signal context creation and cancellation behavior |
| internal/cmd/scan_repo.go | Updated to use signal context with cancellation message handling |
| internal/cmd/scan_image.go | Updated to use signal context with cancellation message handling for both tarball and image scan paths |
| internal/scan/image/image.go | Refactored temp file cleanup using defer to guarantee cleanup on context cancellation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Initialize contexts using signal.NotifyContext to gracefully handle SIGINT and SIGTERM. Pass cancellable context through scanner and HTTP client. Refactor image scanner temp file cleanup to use defer pattern to ensure cleanup runs even when context is cancelled.
Add handleScanError helper that displays "Scan cancelled" when context is cancelled, providing clear feedback when users interrupt scans.
c53dbee to
570508d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use errors.Is to verify the error itself contains context.Canceled rather than just checking the context state. This prevents incorrectly printing "Scan cancelled" when an unrelated error occurs while the context happens to be cancelled. Also adds comprehensive test coverage for handleScanError.
Check error return values from w.Close() and io.Copy() in the captureStderr helper function.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Handle os.Pipe() error in test helper instead of ignoring - Document unused ctx parameter in handleScanError for API consistency
Description
Adds signal-based graceful shutdown support to allow users to cleanly interrupt long-running scans with Ctrl+C. When SIGINT or SIGTERM is received, the context is cancelled, allowing all in-flight operations to terminate and cleanup tasks to run.
Type of Change
Changes
NewSignalContext()utility to initialize contexts with SIGINT/SIGTERM handlingscan_repoandscan_imagecommands to use signal-aware contextsTesting
Verification