Files
containerd/supervisor/task.go
T
Antonio Murdaca b812857db2 supervisor: cancel SendTask when channel is full
This patch handles case c) in https://github.com/moby/moby/issues/31487

(c) A request cannot be added to 's.tasks' because the queue is full.

case b) isn't fixable at this point case there's no way to cancel stuff
from a channel since channels aren't context aware (yet?).
Parallelizing tasks handling isn't easily doable either.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-06-05 19:27:02 +02:00

51 lines
957 B
Go

package supervisor
import (
"context"
"sync"
"github.com/containerd/containerd/runtime"
)
// StartResponse is the response containing a started container
type StartResponse struct {
ExecPid int
Container runtime.Container
}
// Task executes an action returning an error chan with either nil or
// the error from executing the task
type Task interface {
// ErrorCh returns a channel used to report and error from an async task
ErrorCh() chan error
// Ctx carries the context of a task
Ctx() context.Context
}
type baseTask struct {
errCh chan error
ctx context.Context
mu sync.Mutex
}
func (t *baseTask) WithContext(ctx context.Context) {
t.mu.Lock()
defer t.mu.Unlock()
t.ctx = ctx
}
func (t *baseTask) Ctx() context.Context {
t.mu.Lock()
defer t.mu.Unlock()
return t.ctx
}
func (t *baseTask) ErrorCh() chan error {
t.mu.Lock()
defer t.mu.Unlock()
if t.errCh == nil {
t.errCh = make(chan error, 1)
}
return t.errCh
}