Skip to content

Commit

Permalink
Remove context ToBackground util (#7980)
Browse files Browse the repository at this point in the history
Can be replaced with `context.WithoutCancel` added in go 1.21
  • Loading branch information
bduffany authored Dec 2, 2024
1 parent 488a178 commit 0f5f692
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ func (c *FirecrackerContainer) LoadSnapshot(ctx context.Context) error {
c.rmOnce = &sync.Once{}
c.rmErr = nil

vmCtx, cancelVmCtx := context.WithCancelCause(background.ToBackground(ctx))
vmCtx, cancelVmCtx := context.WithCancelCause(context.WithoutCancel(ctx))
c.vmCtx = vmCtx
c.cancelVmCtx = cancelVmCtx

Expand Down Expand Up @@ -1914,7 +1914,7 @@ func (c *FirecrackerContainer) create(ctx context.Context) error {
c.rmOnce = &sync.Once{}
c.rmErr = nil

vmCtx, cancel := context.WithCancelCause(background.ToBackground(ctx))
vmCtx, cancel := context.WithCancelCause(context.WithoutCancel(ctx))
c.vmCtx = vmCtx
c.cancelVmCtx = cancel

Expand Down
7 changes: 0 additions & 7 deletions server/util/background/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ func (ctx *disconnectedContext) Value(key interface{}) interface{} {
return ctx.parent.Value(key)
}

// ToBackground returns a background context from the given context, removing
// any cancellation and deadlines associated with the context, but preserving
// all context values such as auth info and outgoing gRPC metadata.
func ToBackground(ctx context.Context) context.Context {
return newDisconnectedContext(ctx)
}

// Long story short: sometimes you need just a little more time to do a write
// or clean things up, even after a client has cancelled the request (and
// therefore the context) but you still need all the auth credentials and
Expand Down

0 comments on commit 0f5f692

Please sign in to comment.