Skip to content

Commit dfcc594

Browse files
committed
Fix deadlock in Windows runhcs shim exec
Signed-off-by: Justin Terry (VM) <[email protected]>
1 parent f7f24e2 commit dfcc594

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

runtime/v2/runhcs/process.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ func newProcess(ctx context.Context, s *service, id string, pid uint32, pr *pipe
5353
relay: pr,
5454
waitBlock: make(chan struct{}),
5555
}
56+
process.startedWg.Add(1)
5657
go waitForProcess(ctx, process, p, s)
5758
return process, nil
5859
}
5960

61+
// waitForProcess waits for `p` to exit.
62+
//
63+
// The caller of `waitForProcess` MUST have incremented `process.startedWg` to
64+
// synchronize event start/exit publishing.
6065
func waitForProcess(ctx context.Context, process *process, p *os.Process, s *service) {
6166
pid := uint32(p.Pid)
62-
process.startedWg.Add(1)
6367

6468
// Store the default non-exited value for calls to stat
6569
process.exit.Store(&processExit{
@@ -121,7 +125,6 @@ func newExecProcess(ctx context.Context, s *service, cid, id string, pr *pipeRel
121125
relay: pr,
122126
waitBlock: make(chan struct{}),
123127
}
124-
process.startedWg.Add(1)
125128

126129
// Store the default non-exited value for calls to stat
127130
process.exit.Store(&processExit{

runtime/v2/runhcs/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,17 @@ func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.
682682
}
683683
}
684684

685+
// For the exec case increment the startedWg to make sure we publish the
686+
// started event previous to the exit published in `waitForProcess`.
687+
p.startedWg.Add(1)
688+
defer func() {
689+
if err != nil {
690+
// If an exec failure takes place decrement the startedWg so we
691+
// dont get off on counts.
692+
p.startedWg.Done()
693+
}
694+
}()
695+
685696
// ID here is the containerID to exec the process in.
686697
err = rhcs.Exec(ctx, r.ID, procConfig, eopts)
687698
if err != nil {

0 commit comments

Comments
 (0)