louislam/dockge · error · Error

Socket client not connected for endpoint:

Error message

Socket client not connected for endpoint: 

What it means

After finding the socket client, emitToEndpoint() checks client.connected and agentLoggedInList[endpoint]. If the socket is not connected or the agent login has not completed, it retries while within ~10 seconds of firstConnectTime; if still not ready it throws 'Socket client not connected for endpoint: <endpoint>'.

Source

Thrown at backend/agent-manager.ts:275

            // 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");
            }

            if (!ok) {
                log.error("agent-manager", `${endpoint}: Socket client not connected`);
                throw new Error("Socket client not connected for endpoint: " + endpoint);
            }
        }

        client.emit("agent", endpoint, eventName, ...args);
    }

    emitToAllEndpoints(eventName: string, ...args : unknown[]) {
        log.debug("agent-manager", "Emitting event to all endpoints");
        for (let endpoint in this.agentSocketList) {
            this.emitToEndpoint(endpoint, eventName, ...args).catch((e) => {
                log.warn("agent-manager", e.message);
            });
        }
    }

    async sendAgentList() {
        let list = await Agent.getAgentList();
        let result : Record<string, LooseObject> = {};

View on GitHub (pinned to f809ae192b)

Solutions

  1. Check the agent instance is up and reachable (curl its URL/port) and wait for 'connected' status before emitting
  2. Reconnect the agent: call connect() again or recreate the agent entry, since the client may have permanently disconnected after the retry window
  3. Verify agent credentials so the login step completes and agentLoggedInList[endpoint] becomes true

Example fix

// before
await agentManager.emitToEndpoint(endpoint, "startStack", name);
// after
try {
    await agentManager.emitToEndpoint(endpoint, "startStack", name);
} catch (e) {
    if (String(e.message).startsWith("Socket client not connected")) {
        await new Promise(r => setTimeout(r, 3000)); // or trigger reconnect
        await agentManager.emitToEndpoint(endpoint, "startStack", name);
    } else {
        throw e;
    }
}
Defensive patterns

Strategy: retry

Validate before calling

// check agent reachability before emitting
const res = await fetch(`http://${endpoint}`).catch(() => null);
if (!res) throw new Error(`Agent ${endpoint} unreachable`);

Try / catch

try {
    await agentManager.emitToEndpoint(endpoint, eventName, ...args);
} catch (e) {
    if (String(e.message).startsWith("Socket client not connected")) {
        await sleep(3000); // or wait for agentStatus 'connected' event
        await agentManager.emitToEndpoint(endpoint, eventName, ...args);
    } else throw e;
}

Prevention

When it happens

Trigger: emitToEndpoint called while the agent socket is disconnected (network drop, agent Dockge instance down/restarting) or before the agent 'login' handshake finished, and the retry window (firstConnectTime + 10s) elapsed without the socket becoming ready.

Common situations: Remote Dockge agent offline or restarting during a deploy/stack command; wrong credentials so the agent never reaches logged-in state; firewall/network interruption; emitting immediately after page load before the connection+login completes past the 10s grace window.

Related errors


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