-
Notifications
You must be signed in to change notification settings - Fork 119
llama-swap should never need to be restarted due to upstream issues #155
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4d16f76
add experiment to test cmd.CommandContext behaviour
mostlygeek c699aab
Improve healthCheck interruption logic
mostlygeek 1e16c83
move cmd.Wait logic out of Process.start()
mostlygeek 16da4c3
Refactor Process stop logic to use Cancel context
mostlygeek fddc14f
Refactor Process.start() health check logic
mostlygeek 8f68dd6
noop, remove some comments
mostlygeek df36c41
Revise Process lifecycle state machine
mostlygeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "os/signal" | ||
| "syscall" | ||
| "time" | ||
| ) | ||
|
|
||
| /* | ||
| ** | ||
| Test how exec.Cmd.CommandContext behaves under certain conditions:* | ||
| - process is killed externally, what happens with cmd.Wait() * | ||
| ✔︎ it returns. catches crashes.* | ||
| - process ignores SIGTERM* | ||
| ✔︎ `kill()` is called after cmd.WaitDelay* | ||
| - this process exits, what happens with children (kill -9 <this process' pid>)* | ||
| x they stick around. have to be manually killed.* | ||
| - .WithTimeout()'s cancel is called * | ||
| ✔︎ process is killed after it ignores sigterm, cmd.Wait() catches it.* | ||
| - parent receives SIGINT/SIGTERM, what happens | ||
| ✔︎ waits for child process to exit, then exits gracefully. | ||
| */ | ||
| func main() { | ||
|
|
||
| // swap between these to use kill -9 <pid> on the cli to sim external crash | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| //ctx, cancel := context.WithTimeout(context.Background(), 1000*time.Millisecond) | ||
| defer cancel() | ||
|
|
||
| //cmd := exec.CommandContext(ctx, "sleep", "1") | ||
| cmd := exec.CommandContext(ctx, | ||
| "../../build/simple-responder_darwin_arm64", | ||
| "-ignore-sig-term", /* so it doesn't exit on receiving SIGTERM, test cmd.WaitTimeout */ | ||
| ) | ||
| cmd.Stdin = os.Stdin | ||
| cmd.Stdout = os.Stdout | ||
| cmd.Stderr = os.Stderr | ||
|
|
||
| // set a wait delay before signing sig kill | ||
| cmd.WaitDelay = 500 * time.Millisecond | ||
| cmd.Cancel = func() error { | ||
| fmt.Println("✔︎ Cancel() called, sending SIGTERM") | ||
| cmd.Process.Signal(syscall.SIGTERM) | ||
| return nil | ||
| } | ||
|
|
||
| if err := cmd.Start(); err != nil { | ||
| fmt.Println("Error starting process:", err) | ||
| return | ||
| } | ||
|
|
||
| // catch signals. Calls cancel() which will cause cmd.Wait() to return and | ||
| // this program to eventually exit gracefully. | ||
| sigChan := make(chan os.Signal, 1) | ||
| signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
| go func() { | ||
| signal := <-sigChan | ||
| fmt.Printf("✔︎ Received signal: %d, Killing process... with cancel before exiting\n", signal) | ||
| cancel() | ||
| }() | ||
|
|
||
| fmt.Printf("✔︎ Parent Pid: %d, Process Pid: %d\n", os.Getpid(), cmd.Process.Pid) | ||
| fmt.Println("✔︎ Process started, cmd.Wait() ... ") | ||
| if err := cmd.Wait(); err != nil { | ||
| fmt.Println("✔︎ cmd.Wait returned, Error:", err) | ||
| } else { | ||
| fmt.Println("✔︎ cmd.Wait returned, Process exited on its own") | ||
| } | ||
| fmt.Println("✔︎ Child process exited, Done.") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Check error return value from Signal()
The error return value from
cmd.Process.Signalshould be checked, even in test code, to help debug signal delivery issues.cmd.Cancel = func() error { fmt.Println("✔︎ Cancel() called, sending SIGTERM") - cmd.Process.Signal(syscall.SIGTERM) - return nil + if err := cmd.Process.Signal(syscall.SIGTERM); err != nil { + fmt.Printf("Failed to send SIGTERM: %v\n", err) + return err + } + return nil }📝 Committable suggestion
🧰 Tools
🪛 golangci-lint (1.64.8)
52-52: Error return value of
cmd.Process.Signalis not checked(errcheck)
🤖 Prompt for AI Agents