File tree 1 file changed +15
-9
lines changed
1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -132,12 +132,21 @@ func (tio *Timeout) wait(ctx context.Context) *ExitStatus {
132
132
ex := & ExitStatus {}
133
133
cmd := tio .getCmd ()
134
134
exitChan := getExitChan (cmd )
135
- killCh := make (chan struct {})
136
- if tio .KillAfter > 0 {
137
- go func () {
138
- time .Sleep (tio .Duration + tio .KillAfter )
135
+ killCh := make (chan struct {}, 2 )
136
+ done := make (chan struct {})
137
+ defer close (done )
138
+
139
+ delayedKill := func (dur time.Duration ) {
140
+ select {
141
+ case <- done :
142
+ return
143
+ case <- time .After (dur ):
139
144
killCh <- struct {}{}
140
- }()
145
+ }
146
+ }
147
+
148
+ if tio .KillAfter > 0 {
149
+ go delayedKill (tio .Duration + tio .KillAfter )
141
150
}
142
151
for {
143
152
select {
@@ -160,10 +169,7 @@ func (tio *Timeout) wait(ctx context.Context) *ExitStatus {
160
169
// XXX handling etx.Err()?
161
170
tio .terminate ()
162
171
ex .typ = exitTypeCanceled
163
- go func () {
164
- time .Sleep (tio .getKillAfterCancel ())
165
- killCh <- struct {}{}
166
- }()
172
+ go delayedKill (tio .getKillAfterCancel ())
167
173
}
168
174
}
169
175
}
You can’t perform that action at this time.
0 commit comments