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

  1. Confirm connect(url,...) was called and completed for this endpoint before emitting
  2. Check that the endpoint string equals new URL(agentUrl).host exactly (host+port, no scheme/path)
  3. 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

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


AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31). Data as JSON: /api/errors/e097d141526669f8. Report an issue: GitHub.