Skip to content

Commit 5d53119

Browse files
sipsmatonistiigi
authored andcommitted
executor: fix resource sampler goroutine leak
Before this, the runc executor did not close the cgroupRecord when the container exited non-zero, which resulted in goroutines leaking. Signed-off-by: Erik Sipsma <[email protected]> (cherry picked from commit fa11bf9)
1 parent 4b6ca80 commit 5d53119

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

executor/resources/monitor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (r *cgroupRecord) Start() {
5656
r.closeSampler = s.Close
5757
}
5858

59+
func (r *cgroupRecord) Close() {
60+
r.close()
61+
}
62+
5963
func (r *cgroupRecord) CloseAsync(next func(context.Context) error) error {
6064
go func() {
6165
r.close()
@@ -160,6 +164,9 @@ func (r *nopRecord) Samples() (*types.Samples, error) {
160164
return nil, nil
161165
}
162166

167+
func (r *nopRecord) Close() {
168+
}
169+
163170
func (r *nopRecord) CloseAsync(next func(context.Context) error) error {
164171
return next(context.TODO())
165172
}

executor/resources/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
type Recorder interface {
1111
Start()
12+
Close()
1213
CloseAsync(func(context.Context) error) error
1314
Wait() error
1415
Samples() (*Samples, error)

executor/runcexecutor/executor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ func (w *runcExecutor) Run(ctx context.Context, id string, root executor.Mount,
335335

336336
err = exitError(ctx, err)
337337
if err != nil {
338+
if rec != nil {
339+
rec.Close()
340+
}
338341
releaseContainer(context.TODO())
339342
return nil, err
340343
}

0 commit comments

Comments
 (0)