fix: stale agent state crashes resource pool
Band aid fix for resource pool crashing when our local agent state doesn't include an agent that an allocation references.
@@ -353,7 +353,19 @@ func removeTaskFromAgents(
) {
for _, allocation := range resourcesAllocated.Resources {
allocation := allocation.(*containerResources)
+
+ // TODO properly handle this case since this will likely
+ // lead to issues in many cases.
agentState := agents[allocation.agent.Handler]
+ if agentState == nil {
+ log.Errorf("tried to remove an allocation (allocationID: %s containerID: %s) "+
+ "from an agent: (agentID: %+v) but scheduler could not find the agent",
+ allocation.req.AllocationID, allocation.containerID,
+ allocation.agent.Handler.Address().Local(),
+ )
+ continue
+ }
+
agentState.DeallocateContainer(allocation.containerID)
}
}
