Skip to content

Commit 10fa2a4

Browse files
committed
Use Command.WaitDelay to avoid Command.Wait blocking on stdin/out/err
Add WaitDelay to ensure cmd.Wait() returns in a reasonable timeframe if the goroutines that cmd.Start() uses to copy Stdin/Stdout/Stderr are blocked when copying due to a sub-subprocess holding onto them. Read more details in these issues: - golang/go#23019 - golang/go#50436 This isn't the original intent of kill-delay, but it seems reasonable to reuse it in this context. Fixes canonical#149
1 parent 73aa51e commit 10fa2a4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

internals/overlord/servstate/handlers.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,18 @@ func (s *serviceData) startInternal() error {
400400
s.cmd.Stdout = logWriter
401401
s.cmd.Stderr = logWriter
402402

403+
// Add WaitDelay to ensure cmd.Wait() returns in a reasonable timeframe if
404+
// the goroutines that cmd.Start() uses to copy Stdin/Stdout/Stderr are
405+
// blocked when copying due to a sub-subprocess holding onto them. Read
406+
// more details in these issues:
407+
//
408+
// - https://github.com/golang/go/issues/23019
409+
// - https://github.com/golang/go/issues/50436
410+
//
411+
// This isn't the original intent of kill-delay, but it seems reasonable
412+
// to reuse it in this context.
413+
s.cmd.WaitDelay = s.killDelay()
414+
403415
// Start the process!
404416
logger.Noticef("Service %q starting: %s", serviceName, s.config.Command)
405417
err = reaper.StartCommand(s.cmd)
@@ -616,9 +628,9 @@ func (s *serviceData) sendSignal(signal string) error {
616628
}
617629

618630
// killDelay reports the duration that this service should be given when being
619-
// asked to shutdown gracefully before being force terminated. The value
620-
// returned will either be the services pre configured value or the default
621-
// kill delay for pebble.
631+
// asked to shut down gracefully before being force-terminated. The value
632+
// returned will either be the service's pre-configured value, or the default
633+
// kill delay if that is not set.
622634
func (s *serviceData) killDelay() time.Duration {
623635
if s.config.KillDelay.IsSet {
624636
return s.config.KillDelay.Value

0 commit comments

Comments
 (0)