orchestrator: NBD pool ReleaseDevice retry sleep ignores context cancellation
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.6k
- Forks
- 438
- PR merge metrics
- No merged PRs in 30d
Description
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 stoppool.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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/orchestrator/pkg/sandbox/nbd/pool.go around line 369 and read the ReleaseDevice retry loop, then check the callers in path_direct.go:336 and pool.go:395. Confirm that cancellation interrupts the retry delay and returns the context error, including the infinite-retry shutdown paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100