Derive a context for use in operations #17016
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Operations should never be using the request context inside their run function body. The request context may have been cancelled before the operation is started.
When calling
operations.OperationCreate, a context is passed in which is used to set the operationRequestor. The original context is not persisted beyond this.This PR changes the
operations.Operationto remove thecancel.Cancellerin favour of using a cancellable context. The operation context is derived from the daemon shutdown context and has some key information copied from the input context (e.g. the Requestor).I've then updated all operations in LXD to use
(Operation).Context()wherever acontext.Contextargument is called for inside an operation.This is another part of #16613 (comment)