louislam/dockge · error · Error
Socket client not found for endpoint:
Error message
Socket client not found for endpoint:
What it means
emitToEndpoint() resolves the socket.io client for an agent endpoint from this.agentSocketList[endpoint]. If there is no connected client registered under that endpoint key, it logs an error and throws 'Socket client not found for endpoint: <endpoint>' — the agent is not connected at all, so emitting is impossible.
Source
Thrown at backend/agent-manager.ts:253
for (let endpoint in list) {
let agent = list[endpoint];
this.connect(agent.url, agent.username, agent.password);
}
}
disconnectAll() {
for (let endpoint in this.agentSocketList) {
this.disconnect(endpoint);
}
}
async emitToEndpoint(endpoint: string, eventName: string, ...args : unknown[]) {
log.debug("agent-manager", "Emitting event to endpoint: " + endpoint);
let client = this.agentSocketList[endpoint];
if (!client) {
log.error("agent-manager", "Socket client not found for endpoint: " + endpoint);
throw new Error("Socket client not found for endpoint: " + endpoint);
}
if (!client.connected || !this.agentLoggedInList[endpoint]) {
// Maybe the request is too quick, the socket is not connected yet, check firstConnectTime
// If it is within 10 seconds, we should apply retry logic here
let diff = dayjs().diff(this.firstConnectTime, "second");
log.debug("agent-manager", endpoint + ": diff: " + diff);
let ok = false;
while (diff < 10) {
if (client.connected && this.agentLoggedInList[endpoint]) {
log.debug("agent-manager", `${endpoint}: Connected & Logged in`);
ok = true;
break;
}
log.debug("agent-manager", endpoint + ": not ready yet, retrying in 1 second...");
await sleep(1000);
diff = dayjs().diff(this.firstConnectTime, "second");
}View on GitHub (pinned to f809ae192b)
Solutions
- Confirm connect(url,...) was called and completed for this endpoint before emitting
- Check that the endpoint string equals new URL(agentUrl).host exactly (host+port, no scheme/path)
- Verify the agent was not removed (remove() deletes agentSocketList[endpoint]) and that a connect is in progress, then retry after connection is established
Example fix
// before
await agentManager.emitToEndpoint(endpoint, "requestStackList");
// after
if (agentManager.hasEndpoint(endpoint)) { // or track connected endpoints client-side
await agentManager.emitToEndpoint(endpoint, "requestStackList");
} else {
await agentManager.connect(agentUrl, username, password);
await agentManager.emitToEndpoint(endpoint, "requestStackList");
} Defensive patterns
Strategy: try-catch
Validate before calling
const endpoint = new URL(agentUrl).host;
if (!endpoint) throw new Error("Invalid agent URL");
// only emit to endpoints known to be connected
if (!connectedEndpoints.has(endpoint)) {
await agentManager.connect(agentUrl, username, password);
} Type guard
function isValidEndpoint(endpoint: unknown): endpoint is string {
return typeof endpoint === "string" && endpoint.length > 0 && endpoint.includes(":") === false ? new URL("http://" + endpoint).host === endpoint : true;
} Try / catch
try {
await agentManager.emitToEndpoint(endpoint, eventName, ...args);
} catch (e) {
if (String(e.message).startsWith("Socket client not found")) {
// trigger reconnect for this endpoint, then retry once
} else throw e;
} Prevention
- Only emit after the agent status is 'connected'
- Use new URL(url).host as the endpoint key everywhere
- Never emit to endpoints that were removed
- Track connected endpoints client-side before calling emitToAllEndpoints
When it happens
Trigger: emitToEndpoint (or emitToAllEndpoints) called with an endpoint whose connect() was never run, whose client was deleted by remove(), or whose key differs (new URL(url).host vs raw url, port included/omitted) from the key used in agentSocketList.
Common situations: Emitting right after adding an agent before connect() finished; sending commands to an agent that was just removed; race where the frontend emits before the agent list finished loading; URL normalization mismatch so the endpoint string never matches the map key.
Related errors
- Socket client not connected for endpoint:
- Agent not found
- Name must be a string
- Stack name must be a string
AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31).
Data as JSON: /api/errors/e097d141526669f8.
Report an issue: GitHub.