Skip to content

Commit

Permalink
behavior: runtime: fix fast print-then-exit
Browse files Browse the repository at this point in the history
calling process.Delete cancels its IO, so wait on the IO to finish first

fixes #6775

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
  • Loading branch information
vito committed Mar 30, 2021
1 parent e7fec54 commit cee8ff8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions worker/runtime/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func (p *Process) Wait() (int, error) {
return 0, fmt.Errorf("waiting for exit status: %w", err)
}

p.process.IO().Wait()

_, err = p.process.Delete(context.Background())
if err != nil {
return 0, fmt.Errorf("delete process: %w", err)
}

p.process.IO().Wait()

return int(status.ExitCode()), nil
}

Expand Down
6 changes: 6 additions & 0 deletions worker/runtime/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (s *ProcessSuite) TestWaitStatusErr() {

func (s *ProcessSuite) TestProcessWaitDeleteError() {
s.ch <- *containerd.NewExitStatus(0, time.Now(), nil)
s.containerdProcess.IOReturns(s.io)

expectedErr := errors.New("status-err")
s.containerdProcess.DeleteReturns(nil, expectedErr)
Expand All @@ -60,6 +61,11 @@ func (s *ProcessSuite) TestProcessWaitBlocksUntilIOFinishes() {
s.ch <- *containerd.NewExitStatus(0, time.Now(), nil)
s.containerdProcess.IOReturns(s.io)

s.io.WaitStub = func() {
// ensure Wait() is called before Delete() which cancels IO
s.Equal(0, s.containerdProcess.DeleteCallCount())
}

_, err := s.process.Wait()
s.NoError(err)

Expand Down

0 comments on commit cee8ff8

Please sign in to comment.