mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-04 20:06:27 +02:00
fix exitCh race condition (#20817)
This commit is contained in:
parent
82359a9e8f
commit
7f2d3f2c5c
@ -257,7 +257,16 @@ func (s *Server) bounceCmd(newEnvVars []string) error {
|
||||
}
|
||||
s.childProcess = proc
|
||||
|
||||
// listen if the child process exits and bubble it up to the main loop
|
||||
if err := s.childProcess.Start(); err != nil {
|
||||
return fmt.Errorf("error starting the child process: %w", err)
|
||||
}
|
||||
|
||||
s.childProcessState = childProcessStateRunning
|
||||
|
||||
// Listen if the child process exits and bubble it up to the main loop.
|
||||
//
|
||||
// NOTE: this must be invoked after child.Start() to avoid a potential
|
||||
// race condition with ExitCh not being initialized.
|
||||
go func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
s.childProcessExitCodeCloser = cancel
|
||||
@ -270,10 +279,5 @@ func (s *Server) bounceCmd(newEnvVars []string) error {
|
||||
}
|
||||
}()
|
||||
|
||||
if err := s.childProcess.Start(); err != nil {
|
||||
return fmt.Errorf("error starting child process: %w", err)
|
||||
}
|
||||
s.childProcessState = childProcessStateRunning
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user