### Team
- [X] I've assigned a team label to this issue
### Severity
2+… affected customers
### Version
Tested in 2021.2.7650, Reported in 2021.2.7697 and 2021.2.7580
### Latest Version
_No response_
### What happened?
Running many steps/tasks in parallel against the Octopus Server with `OctopusBypassDeploymentMutex` set to `true` can create a `Stack empty` error. I was able to replicate this using `Deploy a Release` steps.
### Reproduction
1. Create 12 or so projects that deploy a simple package (they can be clones of each other)
2. Create an orchestrator project with a matching number of `Deploy a Release` steps
3. Set the variable `OctopusBypassDeploymentMutex` to `true`
4. Create a Release with the orchestrator project
5. Deploy
_If you have trouble reproducing with the above instructions, you can try cloning the orchestrator project and deploying both orchestrator projects at the same time_
### Error and Stacktrace
```shell
Creating deployment for release 0.0.1 of project 'Deployment Proj 2'
14:00:15 Verbose | Stack empty.
| System.InvalidOperationException
| at System.Collections.Generic.Stack`1.ThrowForEmptyStack()
| at System.Collections.Generic.Stack`1.Pop()
| at Octopus.Core.Features.Projects.ProjectScope.ProjectPathDisposable.Dispose() in ProjectScope.cs:line 105
| at Octopus.Server.Orchestration.ServerTasks.Deploy.DeploymentFactory.CreateDeployment(IOctopusQueryExecutor queryExecutor, Deployment deployment, User user, DateTimeOffset queueTime, Nullable`1 queueTimeExpiry, ILifecycleProgressionEvaluator lifecycleProgressionEvaluator, IDeploymentSummaryService deploymentSummaryService, IEnumerable`1 additionalVariables, IPromptedVariableValueProvider promptedVariableValueProvider, Boolean isScheduledDeployment, ILog log) in DeploymentFactory.cs:line 184
| at Octopus.Core.Resources.Deployments.DeploymentCreator.CreateDeployment(DeploymentResource resource, DateTimeOffset queueTime, Boolean isScheduledDeployment, IOctopusQueryExecutor executorAsPrincipal, User user, IPromptedVariableValueProvider promptedVariableValueProvider, ILog log, CancellationToken cancellationToken, IEnumerable`1 additionalVariables) in DeploymentCreator.cs:line 68
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Steps.DeployRelease.DeployReleaseActionHandler.<>c__DisplayClass18_1.<Execute in DeployReleaseActionHandler.cs:line 223
| at Octopus.Server.Infrastructure.Orchestration.UnitsOfWork.UnitOfWorkExecutor.<>c__DisplayClass10_0`2.<Execute in UnitOfWorkExecutor.cs:line 166
| at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.DoAsync[T](IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 43
| at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.DoAsync[T](IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 43
| at Octopus.Server.Infrastructure.Orchestration.UnitsOfWork.UnitOfWorkExecutor.Execute[T1,TResult](Func`3 action, CancellationToken cancellationToken, String name) in UnitOfWorkExecutor.cs:line 167
| at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task`1 task)
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Steps.DeployRelease.DeployReleaseActionHandler.Execute(ActionCommand command, DeploymentTarget machine, ITaskLog taskLog) in DeployReleaseActionHandler.cs:line 220
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Steps.DeployRelease.DeployReleaseActionHandler.Execute(ActionCommand command, ITaskLog taskLog, CancellationToken cancellationToken) in DeployReleaseActionHandler.cs:line 101
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.OldActionDispatcher.<>c__DisplayClass4_0.<DispatchServerAction in OldActionDispatcher.cs:line 42
| at Octopus.Server.Infrastructure.EitherAsyncOrSync.Execute(CancellationToken cancellationToken) in EitherAsyncOrSync.cs:line 38
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Guidance.ExecuteWithoutGuidance(EitherAsyncOrSync callback, String actionName, Boolean actionIsRequiredToRun, ITaskLog taskLog, CancellationToken cancellationToken) in Guidance.cs:line 116
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Guidance.Execute(EitherAsyncOrSync callback, String actionName, Boolean actionIsRequiredToRun, ITaskLog taskLog, Maybe`1 callbackOnExclude, CancellationToken cancellationToken) in Guidance.cs:line 67
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.OldActionDispatcher.DispatchServerAction(ActionCommand command, ITaskLog taskLog, CancellationToken cancellationToken) in OldActionDispatcher.cs:line 37
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.OldActionDispatcher.Dispatch(ActionCommand command, DeploymentTarget deploymentTarget, ITaskLog taskLog, CancellationToken cancellationToken) in OldActionDispatcher.cs:line 27
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.NewActionDispatcher.Dispatch(ActionCommand command, DeploymentTarget deploymentTarget, ITaskLog taskLogForTarget, ITaskLog taskLogRoot, Maybe`1 guidanceExcludeCallback, CancellationToken cancellationToken) in NewActionDispatcher.cs:line 92
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`1.<>c__DisplayClass38_2.<ExecuteActionAndInitLoggingContext in ExecutionTaskController.cs:line 601
| at Octopus.Server.Infrastructure.EitherAsyncOrSync.Execute(CancellationToken cancellationToken) in EitherAsyncOrSync.cs:line 38
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Guidance.ExecuteWithoutGuidance(EitherAsyncOrSync callback, String actionName, Boolean actionIsRequiredToRun, ITaskLog taskLog, CancellationToken cancellationToken) in Guidance.cs:line 116
| at Octopus.Server.Orchestration.ServerTasks.Deploy.Guidance.Execute(EitherAsyncOrSync callback, String actionName, Boolean actionIsRequiredToRun, ITaskLog taskLog, Maybe`1 callbackOnExclude, CancellationToken cancellationToken) in Guidance.cs:line 67
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`1.<>c__DisplayClass38_1.<ExecuteActionAndInitLoggingContext in ExecutionTaskController.cs:line 607
| at Octopus.Server.Infrastructure.Orchestration.UnitsOfWork.UnitOfWorkExecutor.<>c__DisplayClass4_0`2.<Execute in UnitOfWorkExecutor.cs:line 74
| at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.DoAsync(IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 73
| at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.DoAsync(IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 73
| at Octopus.Server.Infrastructure.Orchestration.UnitsOfWork.UnitOfWorkExecutor.Execute[T1,T2](Func`4 action, CancellationToken cancellationToken, String name) in UnitOfWorkExecutor.cs:line 75
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`1.<>c__DisplayClass38_0.<ExecuteActionAndInitLoggingContext in ExecutionTaskController.cs:line 608
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`1.ExecuteWithTransientErrorDetection(Func`2 action, ITaskLog taskLog, CancellationToken cancellationToken, DeploymentTarget deploymentTarget) in ExecutionTaskController.cs:line 753
| at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`1.ExecuteActionAndInitLoggingContext(PlannedStep step, DeploymentTarget targetContext, PlannedAction action, ITaskLog taskLogForTarget, ITaskLog taskLogRoot, CancellationToken cancellationToken) in ExecutionTaskController.cs:line 626
14:00:17 Fatal | The action Deploy a Release 2 on a Worker failed
```
### More Information
Affected Customers:
[Ticket #1](https://help.octopus.com/t/runtime-error-on-deploy-a-release-process-step/27290)
[Ticket #2](https://octopus.zendesk.com/agent/tickets/77788)
### Workaround
Set the variable `OctopusBypassDeploymentMutex` to `false` for projects that run many steps/tasks directly against the Octopus Server