in lambda/rapid/shutdown.go [169:213]
func (s *shutdownContext) shutdownRuntime(execCtx *rapidContext, start time.Time, deadline time.Time) {
// If runtime is started:
// 1. SIGTERM and wait until deadline
// 2. SIGKILL on deadline
log.Debug("Shutting down the runtime.")
name := fmt.Sprintf("%s-%d", runtimeProcessName, execCtx.runtimeDomainGeneration)
exitedChannel, found := s.getExitedChannel(name)
if found {
err := execCtx.supervisor.Terminate(context.Background(), &supvmodel.TerminateRequest{
Domain: RuntimeDomain,
Name: name,
})
if err != nil {
// We are not reporting the error upstream because we will anyway
// shut the domain out at the end of the shutdown sequence
log.WithError(err).Warn("Failed sending Termination signal to runtime")
}
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()
select {
case <-ctx.Done():
log.Warnf("Deadline: The runtime did not exit after deadline %s; Killing it.", deadline)
err = execCtx.supervisor.Kill(context.Background(), &supvmodel.KillRequest{
Domain: RuntimeDomain,
Name: name,
Deadline: time.Now().Add(time.Millisecond * supervisorBlockingMaxMillis),
})
if err != nil {
// We are not reporting the error upstream because we will anyway
// shut the domain out at the end of the shutdown sequence
log.WithError(err).Warn("Failed sending Kill signal to runtime")
}
case <-exitedChannel:
}
} else {
log.Warn("The runtime was not started.")
}
log.Debug("Shutdown the runtime.")
}