Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
agent: allow multiple waitProcess()
Browse files Browse the repository at this point in the history
There will be multiple waitProcess() requests
issued before process exits, and all those requests
should be fulfilled.

Fixes: #129
Fixes: #333

Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Aug 30, 2018
1 parent 46396d2 commit f746ed8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type process struct {
consoleSock *os.File
termMaster *os.File
exitCodeCh chan int
sync.Once
stdinClosed bool
}

Expand Down
9 changes: 7 additions & 2 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,17 +768,22 @@ func (a *agentGRPC) WaitProcess(ctx context.Context, req *pb.WaitProcessRequest)
return &pb.WaitProcessResponse{}, err
}

defer func() {
defer proc.Do(func() {
proc.closePostExitFDs()
ctr.deleteProcess(proc.id)
}()
})

// Using helper function wait() to deal with the subreaper.
libContProcess := (*reaperLibcontainerProcess)(&(proc.process))
exitCode, err := a.sandbox.subreaper.wait(proc.exitCodeCh, libContProcess)
if err != nil {
return &pb.WaitProcessResponse{}, err
}
//refill the exitCodeCh with the exitcode which can be read out
//by another WaitProcess(). Since this channel isn't be closed,
//here the refill will always success and it will be free by GC
//once the process exits.
proc.exitCodeCh <- exitCode

return &pb.WaitProcessResponse{
Status: int32(exitCode),
Expand Down
2 changes: 0 additions & 2 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ func (r *agentReaper) reap() error {
// of the process and return the exit code to the
// caller of WaitProcess().
exitCodeCh <- status

close(exitCodeCh)
}
}

Expand Down

0 comments on commit f746ed8

Please sign in to comment.