mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
*: should return exitCode even if cmd isn't nil
For the pkg/expect package, if the process has been stopped but there is no `Close()` call, the `ExitCode()` won't return exit code correctly. The `ExitCode()` should check `exitErr` and return exit code if cmd isn't nil. And introduces `exitCode` to return correct exit code based on the process is signaled or exited. Signed-off-by: Wei Fu <fuweid89@gmail.com>
This commit is contained in:
@@ -246,7 +246,14 @@ func (ep *EtcdServerProcess) Wait(ctx context.Context) error {
|
||||
defer close(ch)
|
||||
if ep.proc != nil {
|
||||
ep.proc.Wait()
|
||||
ep.cfg.lg.Info("server exited", zap.String("name", ep.cfg.Name))
|
||||
|
||||
exitCode, exitErr := ep.proc.ExitCode()
|
||||
|
||||
ep.cfg.lg.Info("server exited",
|
||||
zap.String("name", ep.cfg.Name),
|
||||
zap.Int("code", exitCode),
|
||||
zap.Error(exitErr),
|
||||
)
|
||||
}
|
||||
}()
|
||||
select {
|
||||
@@ -262,11 +269,16 @@ func (ep *EtcdServerProcess) IsRunning() bool {
|
||||
if ep.proc == nil {
|
||||
return false
|
||||
}
|
||||
_, err := ep.proc.ExitCode()
|
||||
|
||||
exitCode, err := ep.proc.ExitCode()
|
||||
if err == expect.ErrProcessRunning {
|
||||
return true
|
||||
}
|
||||
ep.cfg.lg.Info("server exited", zap.String("name", ep.cfg.Name))
|
||||
|
||||
ep.cfg.lg.Info("server exited",
|
||||
zap.String("name", ep.cfg.Name),
|
||||
zap.Int("code", exitCode),
|
||||
zap.Error(err))
|
||||
ep.proc = nil
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user