Skip to content

Commit c095d11

Browse files
authored
[supervisor] init: Add logging around termination (#20380)
1 parent c9c6726 commit c095d11

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

components/supervisor/cmd/init.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ var initCmd = &cobra.Command{
140140
select {
141141
case <-supervisorDone:
142142
// supervisor has ended - we're all done here
143+
defer log.Info("supervisor has ended (supervisorDone)")
143144
return
144145
case <-sigInput:
145146
ignoreUnexpectedExitCode.Store(true)
@@ -160,8 +161,10 @@ var initCmd = &cobra.Command{
160161
select {
161162
case <-ctx.Done():
162163
// Time is up, but we give all the goroutines a bit more time to react to this.
163-
time.Sleep(time.Millisecond * 500)
164+
time.Sleep(time.Millisecond * 1000)
165+
defer log.Info("supervisor has ended (ctx.Done)")
164166
case <-terminationDone:
167+
defer log.Info("supervisor has ended (terminationDone)")
165168
}
166169
slog.write("Finished shutting down all processes.")
167170
}
@@ -229,10 +232,12 @@ type shutdownLoggerImpl struct {
229232

230233
func (l *shutdownLoggerImpl) write(s string) {
231234
if l.file != nil {
232-
_, err := l.file.WriteString(fmt.Sprintf("[%s] %s \n", time.Since(l.startTime), s))
235+
msg := fmt.Sprintf("[%s] %s \n", time.Since(l.startTime), s)
236+
_, err := l.file.WriteString(msg)
233237
if err != nil {
234238
log.WithError(err).Error("couldn't write to log file")
235239
}
240+
log.Infof("slog: %s", msg)
236241
} else {
237242
log.Debug(s)
238243
}
@@ -250,6 +255,7 @@ func (l *shutdownLoggerImpl) TerminateSync(ctx context.Context, pid int) {
250255
if err != nil {
251256
l.write(fmt.Sprintf("Couldn't obtain process information for PID %d.", pid))
252257
} else if stat.State == "Z" {
258+
l.write(fmt.Sprintf("Process %s with PID %d is a zombie, skipping termination.", stat.Comm, pid))
253259
return
254260
} else {
255261
l.write(fmt.Sprintf("Terminating process %s with PID %d (state: %s, cmdlind: %s).", stat.Comm, pid, stat.State, fmt.Sprint(proc.CmdLine())))

0 commit comments

Comments
 (0)