--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b99a53f4-732a-489c-be6e-572354cf7386n%40googlegroups.com.
It sounds as if you might be running your "REST endpoint" program from an interactive shell (i.e., a terminal) and sending SIGTERM by pressing something like Ctrl-C. Interactive job control, which includes how signals generated by a "terminal" are handled, is a complex topic. So we need to know how you are sending SIGTERM to your process. Is it by something like the `kill` command or syscall to a specific PID or by pressing keys on your terminal to terminate the process?
The application is installed as a service and managed via systemctl start/stop.
There are two types of children -- one type simply runs and then exits: It's run like this...
The other type is long-running and communicates via stdin/stdout: It's run like this...
type LongRunningPredictor struct {theCommand *exec.Cmdinput io.WriteCloseroutput bytes.BuffercompletionError errorhasEnded bool}
func (p *LongRunningPredictor) waitLoop() {p.hasEnded = falsep.completionError = p.theCommand.Wait()p.hasEnded = true}func (p *LongRunningPredictor) start() string {p.theCommand = exec.Command("./long-running-predictor", "trained-model")p.theCommand.Stdout = &p.outputp.theCommand.Stderr = &p.outputp.input, _ = p.theCommand.StdinPipe()p.theCommand.Start()startupText, _ := readLinesUpToPrefixBestEffort(&p.output, "Ready")go p.waitLoop()return startupText}
Long running predictors are cycled through a channel that acts
like a pool -- when one is needed it's pulled from the channel,
and when it's done it's put back to be re-used.
===
Once the rest endpoint app gets the signal to terminate these children are killed even though, in theory, the signal was captured.
I know the signal was captured because the logic I have in place for a clean shutdown begins to execute as expected.
Looking forward to a solution or at least an understanding.
Best,
_M