{"record":{"id":"8f9a0af2005a4722","repo":"theonedev/onedev","slug":"cannot-find-server-managing-allocated-agent-pleas","errorCode":null,"errorMessage":"Cannot find server managing allocated agent, please retry later","messagePattern":"Cannot find server managing allocated agent, please retry later","errorType":"error_code","errorClass":"ExplicitException","httpStatus":400,"severity":"warning","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultResourceService.java","lineNumber":307,"sourceCode":"\t\t\tif (pinnedAgentId != null) {\n\t\t\t\tagentIds = new HashSet<>();\n\t\t\t\tvar agent = agentService.get(pinnedAgentId);\n\t\t\t\tif (agent != null && agent.isOnline() && !agent.isPaused())\n\t\t\t\t\tagentIds.add(pinnedAgentId);\n\t\t\t} else {\n\t\t\t\tagentIds = agentService.query(agentQuery, 0, MAX_VALUE)\n\t\t\t\t\t\t.stream().filter(it -> it.isOnline() && !it.isPaused())\n\t\t\t\t\t\t.map(AbstractEntity::getId)\n\t\t\t\t\t\t.collect(toSet());\n\t\t\t}\n\t\t\tvar agentIdString = allocateNode(\n\t\t\t\t\tagentIds.stream().map(Object::toString).collect(toList()),\n\t\t\t\t\tresourceName, totalConcurrency, requiredConcurrency);\n\t\t\tvar agentId = agentIdString != null? Long.valueOf(agentIdString): null;\n\t\t\tif (agentId != null) {\n\t\t\t\tvar server = agentService.getAgentServer(agentId);\n\t\t\t\tif (server == null)\n\t\t\t\t\tthrow new ExplicitException(\"Cannot find server managing allocated agent, please retry later\");\n\n\t\t\t\treturn clusterService.submitToServer(server, () -> {\n\t\t\t\t\tvar effectiveTotalConcurrency = getEffectiveTotalConcurrency(agentIdString, totalConcurrency);\n\t\t\t\t\tvar concurrencyKey = agentId + \":\" + resourceName;\n\t\t\t\t\tacquireConcurrency(concurrencyKey, effectiveTotalConcurrency, requiredConcurrency);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tupdateLastUsedDate(agentId);\n\t\t\t\t\t\treturn task.call(agentId);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\treleaseConcurrency(concurrencyKey, requiredConcurrency);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tThread.sleep(1000);\n\t\t\t} catch (InterruptedException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultResourceService.java#L289-L325","documentation":"DefaultResourceService.submitAgentTask() allocates an agent by id from a pool, then looks up the server managing that agent via agentService.getAgentServer(agentId). If the lookup returns null — the agent's managing server is unknown at that moment (agent/server registration lag or stale allocation data) — an ExplicitException tells the caller to retry later.","triggerScenarios":"Calling submitAgentTask() when the allocated agent id has no registered managing server in the cluster, e.g. the server record was not yet synced or the agent/server entry is stale during cluster startup or failover.","commonSituations":"Submitting build-agent tasks right after a cluster node joins/restarts before server registration completes; k8s/cloud bursts where agents register faster than server metadata; load-balanced fleet with temporarily inconsistent agent-server mapping.","solutions":["Retry submitAgentTask() after a short backoff — the message explicitly says 'please retry later'","Verify the agent and its server are online in the cluster admin page; restart/re-register the agent if stale","Check server cluster connectivity (ports, tokens) so server registration completes promptly","Upgrade/inspect OneDev server logs for agent registration errors during startup"],"exampleFix":"// before\nresourceService.submitAgentTask(task); // may throw on transient state\n// after\nfor (int i = 0; i < 5; i++) {\n    try { resourceService.submitAgentTask(task); break; }\n    catch (ExplicitException e) {\n        if (!e.getMessage().contains(\"Cannot find server managing allocated agent\")) throw e;\n        Thread.sleep(2000L << i);\n    }\n}","handlingStrategy":"retry","validationCode":"// Pre-check agent/server health before submitting\nvar server = agentService.getAgentServer(agentId);\nif (server == null) scheduleRetry(task);","typeGuard":null,"tryCatchPattern":"try {\n    resourceService.submitAgentTask(task);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"Cannot find server managing allocated agent\"))\n        retryWithBackoff(task, 5);\n    else throw e;\n}","preventionTips":["Implement exponential backoff for agent task submission","Monitor cluster server registration on startup/failover","Ensure agent-server connectivity (ports, tokens) before submitting tasks"],"tags":["cluster","agent","transient","retry","onedev"],"backgroundTag":"request-timeout","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}