X Tutup
Skip to content

Commit 101d4b7

Browse files
committed
Add timeout to task state calls
Fixes containerd#3440 This also returns the task that times out or has an error on the state call in an UNKNOWN status so that the user can manually kill and remove the task. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent f776141 commit 101d4b7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

services/tasks/local.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,18 @@ func (l *local) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest,
266266
}, nil
267267
}
268268

269-
func processFromContainerd(ctx context.Context, p runtime.Process) (*task.Process, error) {
269+
func getProcessState(ctx context.Context, p runtime.Process) (*task.Process, error) {
270+
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
271+
defer cancel()
272+
270273
state, err := p.State(ctx)
271274
if err != nil {
272-
return nil, err
275+
if errdefs.IsNotFound(err) {
276+
return nil, err
277+
}
278+
log.G(ctx).WithError(err).Errorf("get state for %s", p.ID())
273279
}
274-
var status task.Status
280+
status := task.StatusUnknown
275281
switch state.Status {
276282
case runtime.CreatedStatus:
277283
status = task.StatusCreated
@@ -310,7 +316,7 @@ func (l *local) Get(ctx context.Context, r *api.GetRequest, _ ...grpc.CallOption
310316
return nil, errdefs.ToGRPC(err)
311317
}
312318
}
313-
t, err := processFromContainerd(ctx, p)
319+
t, err := getProcessState(ctx, p)
314320
if err != nil {
315321
return nil, errdefs.ToGRPC(err)
316322
}
@@ -333,7 +339,7 @@ func (l *local) List(ctx context.Context, r *api.ListTasksRequest, _ ...grpc.Cal
333339

334340
func addTasks(ctx context.Context, r *api.ListTasksResponse, tasks []runtime.Task) {
335341
for _, t := range tasks {
336-
tt, err := processFromContainerd(ctx, t)
342+
tt, err := getProcessState(ctx, t)
337343
if err != nil {
338344
if !errdefs.IsNotFound(err) { // handle race with deletion
339345
log.G(ctx).WithError(err).WithField("id", t.ID()).Error("converting task to protobuf")

0 commit comments

Comments
 (0)
X Tutup