-
Notifications
You must be signed in to change notification settings - Fork 250
fix(install): cancel root context when receiving an OS signal #810
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
Conversation
6eea248
to
4a5833f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds proper signal handling to the kagent CLI to cancel the root context when receiving OS signals like CTRL+C or SIGTERM. This ensures graceful shutdown throughout the application when users interrupt the process.
- Adds signal handling for OS interrupt signals (CTRL+C, SIGINT, SIGTERM)
- Implements context cancellation when signals are received
- Adds error message output when the application exits with an error
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
fmt.Fprintf(os.Stderr, "kagent aborted.\n") | ||
fmt.Fprintf(os.Stderr, "Exiting.\n") | ||
|
||
cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cancel() function is called in a goroutine without any synchronization mechanism. This could lead to a race condition where the main goroutine exits before the signal handler completes, potentially causing the process to terminate before cleanup is finished. Consider using sync.WaitGroup or another synchronization mechanism to ensure proper cleanup.
Copilot uses AI. Check for mistakes.
Signed-off-by: Tom Morelly <tom.morelly@cba.com.au>
4a5833f
to
3a340e8
Compare
I believe on:
pull_request_target: should fix it |
We originally thought that, but that doesn't work as expected. We are going to mock those calls in the future. |
…-dev#810) This PR introduces actually cancelling the root context when receiving an OS signal such as CTRL+C so that the context is cancelled throughout the `kagent` CLI Signed-off-by: Tom Morelly <tom.morelly@cba.com.au> Co-authored-by: Tom Morelly <tom.morelly@cba.com.au>
This PR introduces actually cancelling the root context when receiving an OS signal such as CTRL+C so that the context is cancelled throughout the
kagent
CLI