Usage of context.Context in gRPC for deferred operations
While executing gRPC calls the backend could require to do some initialisation work before it can start execution of the one or another operation (like git fetch, etc). Once the operation is done we require to revert changes we done as initialisation work. In that case we are not allowed to use context.Context bound to the gRPC call as it could expire or it could be cancelled due to user request. If we use cancelled context the operation will fail and nothing will be reverted back. At the same time we require to use context as it has a lot of "values" set on it as logging, monitoring, features, etc.
Example of the above
{
"level": "error",
"error": "wait for 'worktree remove': signal: terminated",
"correlation_id": "Vw34DxvEMk",
"msg": "failed to remove worktree",
"worktree_name": "squash-77111982-YI3rHPiqEh7guQVvOUCLp0yT2dG1SJow",
"grpc.request.fullMethod": "/gitaly.OperationService/UserSquash",
"grpc.request.repoPath": "@hashed/1e/ac/1eac276ef9248598dc0841685b606d56441cc8b7468b6912096fffc03aa339f6.git"
}