Add lock around task cgroup
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
2b1c915f82
commit
e830112efd
@ -4,6 +4,7 @@ package linux
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -23,6 +24,7 @@ import (
|
|||||||
|
|
||||||
// Task on a linux based system
|
// Task on a linux based system
|
||||||
type Task struct {
|
type Task struct {
|
||||||
|
mu sync.Mutex
|
||||||
id string
|
id string
|
||||||
pid int
|
pid int
|
||||||
shim *client.Client
|
shim *client.Client
|
||||||
@ -72,7 +74,9 @@ func (t *Task) Info() runtime.TaskInfo {
|
|||||||
|
|
||||||
// Start the task
|
// Start the task
|
||||||
func (t *Task) Start(ctx context.Context) error {
|
func (t *Task) Start(ctx context.Context) error {
|
||||||
|
t.mu.Lock()
|
||||||
hasCgroup := t.cg != nil
|
hasCgroup := t.cg != nil
|
||||||
|
t.mu.Unlock()
|
||||||
r, err := t.shim.Start(ctx, &shim.StartRequest{
|
r, err := t.shim.Start(ctx, &shim.StartRequest{
|
||||||
ID: t.id,
|
ID: t.id,
|
||||||
})
|
})
|
||||||
@ -85,7 +89,9 @@ func (t *Task) Start(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
t.mu.Lock()
|
||||||
t.cg = cg
|
t.cg = cg
|
||||||
|
t.mu.Unlock()
|
||||||
if err := t.monitor.Monitor(t); err != nil {
|
if err := t.monitor.Monitor(t); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -285,6 +291,8 @@ func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error)
|
|||||||
|
|
||||||
// Metrics returns runtime specific system level metric information for the task
|
// Metrics returns runtime specific system level metric information for the task
|
||||||
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
||||||
|
t.mu.Lock()
|
||||||
|
defer t.mu.Unlock()
|
||||||
if t.cg == nil {
|
if t.cg == nil {
|
||||||
return nil, errors.Wrap(errdefs.ErrNotFound, "cgroup does not exist")
|
return nil, errors.Wrap(errdefs.ErrNotFound, "cgroup does not exist")
|
||||||
}
|
}
|
||||||
@ -297,6 +305,8 @@ func (t *Task) Metrics(ctx context.Context) (interface{}, error) {
|
|||||||
|
|
||||||
// Cgroup returns the underlying cgroup for a linux task
|
// Cgroup returns the underlying cgroup for a linux task
|
||||||
func (t *Task) Cgroup() (cgroups.Cgroup, error) {
|
func (t *Task) Cgroup() (cgroups.Cgroup, error) {
|
||||||
|
t.mu.Lock()
|
||||||
|
defer t.mu.Unlock()
|
||||||
if t.cg == nil {
|
if t.cg == nil {
|
||||||
return nil, errors.Wrap(errdefs.ErrNotFound, "cgroup does not exist")
|
return nil, errors.Wrap(errdefs.ErrNotFound, "cgroup does not exist")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user