Skip to content

Commit

Permalink
executor: fix resource sampler goroutine leak
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sipsma committed Jul 31, 2023
1 parent 9da03ce commit fa11bf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions executor/resources/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (r *cgroupRecord) Start() {
r.closeSampler = s.Close
}

func (r *cgroupRecord) Close() {
r.close()
}

func (r *cgroupRecord) CloseAsync(next func(context.Context) error) error {
go func() {
r.close()
Expand Down Expand Up @@ -160,6 +164,9 @@ func (r *nopRecord) Samples() (*types.Samples, error) {
return nil, nil
}

func (r *nopRecord) Close() {
}

func (r *nopRecord) CloseAsync(next func(context.Context) error) error {
return next(context.TODO())
}
Expand Down
1 change: 1 addition & 0 deletions executor/resources/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

type Recorder interface {
Start()
Close()
CloseAsync(func(context.Context) error) error
Wait() error
Samples() (*Samples, error)
Expand Down
3 changes: 3 additions & 0 deletions executor/runcexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ func (w *runcExecutor) Run(ctx context.Context, id string, root executor.Mount,

err = exitError(ctx, err)
if err != nil {
if rec != nil {
rec.Close()
}
releaseContainer(context.TODO())
return nil, err
}
Expand Down

0 comments on commit fa11bf9

Please sign in to comment.