File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ func (e *execProcess) setExited(status int) {
9494}
9595
9696func (e * execProcess ) delete (ctx context.Context ) error {
97- e .wg . Wait ( )
97+ waitTimeout ( ctx , & e .wg , 2 * time . Second )
9898 if e .io != nil {
9999 for _ , c := range e .closers {
100100 c .Close ()
Original file line number Diff line number Diff line change 1919package proc
2020
2121import (
22+ "context"
2223 "encoding/json"
2324 "io"
2425 "os"
2526 "strings"
27+ "sync"
2628 "time"
2729
2830 "github.com/containerd/containerd/errdefs"
@@ -104,3 +106,21 @@ func checkKillError(err error) error {
104106func hasNoIO (r * CreateConfig ) bool {
105107 return r .Stdin == "" && r .Stdout == "" && r .Stderr == ""
106108}
109+
110+ // waitTimeout handles waiting on a waitgroup with a specified timeout.
111+ // this is commonly used for waiting on IO to finish after a process has exited
112+ func waitTimeout (ctx context.Context , wg * sync.WaitGroup , timeout time.Duration ) error {
113+ ctx , cancel := context .WithTimeout (ctx , timeout )
114+ defer cancel ()
115+ done := make (chan struct {}, 1 )
116+ go func () {
117+ wg .Wait ()
118+ close (done )
119+ }()
120+ select {
121+ case <- done :
122+ return nil
123+ case <- ctx .Done ():
124+ return ctx .Err ()
125+ }
126+ }
You can’t perform that action at this time.
0 commit comments