Skip to content

orchestrator: NBD pool ReleaseDevice retry sleep ignores context cancellation #3347

Description

@AdaAibaby

Problem

In packages/orchestrator/pkg/sandbox/nbd/pool.go:369, the ReleaseDevice retry loop calls time.Sleep(500 * time.Millisecond) which is not interruptible by context cancellation:

// pool.go:360-370 (simplified)
for {
    select {
    case <-ctx.Done():   // ← only checked at TOP of loop
        return ctx.Err()
    default:
    }
    attempt++
    err := d.release(ctx, idx)
    if err == nil { return nil }
    // ...
    time.Sleep(500 * time.Millisecond)  // ← BUG: ctx cancellation not checked here
}

When the orchestrator shuts down and the shutdown context is cancelled, any goroutine blocked inside this sleep will not wake up for up to 500 ms per retry. With WithInfiniteRetry() enabled (used by both DirectPathMount.Close and DevicePool.Close), a single stuck device can stall the shutdown for an unbounded number of 500 ms sleeps before the context cancel is noticed.

Affected callers

  • path_direct.go:336: ReleaseDevice(ctx, idx, WithInfiniteRetry()) — called on every sandbox stop
  • pool.go:395: ReleaseDevice(ctx, slot, WithInfiniteRetry(), WithTimeout(devicePoolCloseReleaseTimeout)) — called on pool close

Fix

Replace time.Sleep with a context-aware select:

timer := time.NewTimer(500 * time.Millisecond)
select {
case <-ctx.Done():
    timer.Stop()
    return ctx.Err()
case <-timer.C:
}

This change exists in the local branch fix/nbd-pool-release-retry-ctx but has not been merged to main.

Impact

Delayed orchestrator shutdown when NBD devices fail to release. Under normal conditions (device releases cleanly on first attempt) there is no impact.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions