8000 Fix commands that hang · symfony-cli/symfony-cli@ca16375 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca16375

Browse files
committed
Fix commands that hang
1 parent 2e57811 commit ca16375

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

local/runner.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -254,36 +254,23 @@ func (r *Runner) Run() error {
254254
logger.Debug().Msg("Removing pid file")
255255
return r.pidFile.Remove()
256256
}
257-
logger.Debug().Msg("Looping")
258257

259-
// Command is set up to restart on exit (usually PHP builtin
260-
// server), so we restart immediately without waiting
258+
// Command is set up to restart on exit (usually PHP builtin server)
261259
if r.AlwaysRestartOnExit {
262-
logger.Error().Msg("command exited, restarting it immediately")
260+
logger.Debug().Msg("Looping")
261+
// In case of error we want to wait up-to 5 seconds before
262+
// restarting the command, this avoids overloading the system with a
263+
// failing command
264+
if err != nil {
265+
logger.Error().Msgf(`command exited: %s, waiting 5 seconds before restarting it`, err)
266+
timer.Reset(5 * time.Second)
267+
} else {
268+
logger.Error().Msg("command exited, restarting it immediately")
269+
}
263270
continue
264271
}
265272

266-
// In case of error we want to wait up-to 5 seconds before
267-
// restarting the command, this avoids overloading the system with a
268-
// failing command
269-
if err != nil {
270-
logger.Error().Msgf(`command exited: %s, waiting 5 seconds before restarting it`, err)
271-
timer.Reset(5 * time.Second)
272-
}
273-
274-
// Wait for a timer to expire or a file to be changed to restart
275-
// or a signal to be received to exit
276-
logger.Debug().Msg("Waiting for channels")
277-
select {
278-
case sig := <-sigChan:
279-
logger.Info().Msgf(`Signal "%s" received, exiting`, sig)
280-
return nil
281-
case <-restartChan:
282-
logger.Debug().Msg("Received restart")
283-
timer.Stop()
284-
case <-timer.C:
285-
logger.Debug().Msg("Received timer message")
286-
}
273+
return nil
287274
}
288275

289276
logger.Info().Msg("Restarting command")

0 commit comments

Comments
 (0)
0