Thank you for your response!
This is the first time this issue has happened to me. Normally my script is able to delete the Workers just fine.
I found this link: Unable to delete worker - #2 by trond and it had the suggestion to delete the relevant rows from the WorkerTaskLease
table. While not an easily automatable solution, we manually tried it out and it fixed my current issue (I was able to delete the workers).
If this issue repeats then I think it will be worth digging into, but I am hoping it was an isolated incident. For now, lets not worry about it unless it happens again.
For reference:
- Both tasks that caused the workers to stay locked had timed out. My guess is that this error caused the lock to not get released (locking and releasing can be tricky business). This was the error message for both tasks:
A request was sent to a polling endpoint, but the polling endpoint did not collect the request within the allowed time (00:02:00), so the request timed out.
Error Call Stack
Server exception: System.TimeoutException: A request was sent to a polling endpoint, but the polling endpoint did not collect the request within the allowed time (00:02:00), so the request timed out.
Halibut.HalibutClientException
at Halibut.ServiceModel.HalibutProxy.EnsureNotError(ResponseMessage responseMessage)
at Halibut.ServiceModel.HalibutProxy.Invoke(MethodInfo targetMethod, Object[] args)
at System.Reflection.DispatchProxyGenerator.Invoke(Object[] args)
at generatedProxy_1.StartScript(StartScriptCommand )
at Octopus.Server.Orchestration.Targets.Tentacles.TentacleRemoteEndpointFacade.ExecuteCommand(StartScriptCommand command, ITaskLog taskLog) in TentacleRemoteEndpointFacade.cs:line 62
at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionExecution.Immediate.ExecutionTargets.TentacleExecutionTarget.Execute(ScriptCollection bootstrapperScripts, IReadOnlyList`1 bootstrapperArguments, IReadOnlyList`1 files, Nullable`1 forceIsolationLevel, Boolean raw, ITaskLog taskLog, String isolationMutexName, Nullable`1 isolationMutexTimeout) in TentacleExecutionTarget.cs:line 69
at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionExecution.Immediate.ImmediateExecutor.ExecuteCalamari(CalamariFlavour calamariFlavour, String calamariCommand, IReadOnlyList`1 calamariArguments, IReadOnlyList`1 files, IReadOnlyList`1 deploymentTools, VariableCollection extraVariables, TargetManifest targetManifest, CalamariPlatformConstraint calamariPlatformConstraint, Nullable`1 isolationMutexTimeout, String isolationMutexName, ITaskLog taskLog) in ImmediateExecutor.cs:line 160
at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionExecution.CommandBuilders.CalamariCommandBuilder.Execute(ITaskLog taskLog) in CalamariCommandBuilder.cs:line 172
at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.AdHocActionDispatcher.InvokeActionHandler(Machine target, ActionHandlerInvocation actionHandler, ActionAndTargetScopedVariables actionAndTargetScopedVariables, IExecutor executor, TargetManifest targetManifest, ITaskLog taskLog) in AdHocActionDispatcher.cs:line 210
at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.AdHocActionDispatcher.ExecuteOnWorker(TargetManifest targetManifest, Worker worker, ActionHandlerInvocation actionHandler, ITaskLog taskLog) in AdHocActionDispatcher.cs:line 109
at Octopus.Server.Orchestration.ServerTasks.Deploy.ActionDispatch.AdHocActionDispatcher.Dispatch(Machine machine, ActionHandlerInvocation actionHandler, ITaskLog taskLog, VariableCollection variables) in AdHocActionDispatcher.cs:line 57
at Octopus.Server.Orchestration.ServerTasks.Deploy.PackageLockReleaser.ReleasePackageLock(Machine machine, String taskId, ITaskLog taskLog) in PackageLockReleaser.cs:line 37
at Octopus.Core.Extensions.EnumerableExtensionMethods.<>c__DisplayClass6_0`1.<Do>b__0(T item) in EnumerableExtensionMethods.cs:line 89
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at Octopus.Core.Extensions.EnumerableExtensionMethods.Done[T](IEnumerable`1 items) in EnumerableExtensionMethods.cs:line 108
at Octopus.Server.Orchestration.Workers.WorkerReleaser.Release(ITaskLog taskLog, ITaskContext taskContext, AcquiredPackageMap acquiredPackages) in WorkerReleaser.cs:line 27
at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`3.<ExecuteBase>b__16_0(IWorkerReleaser workerReleaser, CancellationToken _) in ExecutionTaskController.cs:line 97
at Octopus.Server.Infrastructure.Orchestration.UnitsOfWork.UnitOfWorkExecutor.<>c__DisplayClass3_0`1.<Execute in UnitOfWorkExecutor.cs:line 87
at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.Do(IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 75
at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.Do(IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 75
at Octopus.Server.Infrastructure.Orchestration.UnitsOfWork.UnitOfWorkExecutor.Execute[T](Func`3 action, CancellationToken cancellationToken, String name) in UnitOfWorkExecutor.cs:line 90
at Octopus.Server.Orchestration.ServerTasks.Deploy.ExecutionTaskController`3.ExecuteBase(CancellationToken cancellationToken) in ExecutionTaskController.cs:line 92
at Octopus.Server.Orchestration.ServerTasks.Deploy.RunbookRunTaskController.Execute(CancellationToken cancellationToken) in RunbookRunTaskController.cs:line 56
at Octopus.Server.Orchestration.ServerTasks.RunningTask.<>c__DisplayClass31_1.<WorkerTask in RunningTask.cs:line 188
at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.Do(IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 75
at Octopus.Core.Infrastructure.UnitsOfWork.UnitOfWorkExtensionMethods.Do(IUnitOfWork unitOfWork, Func`1 action, CancellationToken cancellationToken, String name) in UnitOfWorkExtensionMethods.cs:line 75
at Octopus.Server.Orchestration.ServerTasks.RunningTask.WorkerTask(CancellationToken cancellationToken) in RunningTask.cs:line 221
-
I am using Octopus Server 2022.2.6895. The worker is a Docker Container running in Kubernetes. I am using version 6.1.1409 of the Docker Tentacle container image. (Though I do update Calamari when it starts up, not sure if Calamari is related to the Tentacle version.)
-
This is the part of the script that I use to delete the workers:
# Get the workers in the WorkerPool
$workers = Invoke-RestMethod -Method Get -Uri "$octopusUrl/api/$spaceId/workerpools/$kubernetesWorkerPoolId/workers" -Headers $headers
if ($isTestRun -eq $false)
{
# Delete the workers in the WorkerPool
$workers.Items | ForEach-Object -Process {
Write-Output "Deleting Worker $($_.Id)"
Invoke-RestMethod -Method Delete -Uri "$octopusUrl/api/$spaceId/workers/$($_.Id)" -Headers $headers
}
}