{"record":{"id":"ae824f7bbeef9d1b","repo":"t8y2/dbx","slug":"agent-session-limit-reached-d","errorCode":null,"errorMessage":"agent session limit reached: %d","messagePattern":"agent session limit reached: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/cassandra-go/main.go","lineNumber":246,"sourceCode":"\t\tdefer session.mu.Unlock()\n\t\trelease, err := session.server.runtime.acquire(isMetadataOperation(method))\n\t\tif err != nil {\n\t\t\treturn nil, false, err\n\t\t}\n\t\tdefer release()\n\t\treturn session.server.dispatch(method, params)\n\t}\n}\n\nfunc (r *runtimeServer) openSession(id string, cp connectParams) error {\n\tr.mu.Lock()\n\tif _, exists := r.sessions[id]; exists {\n\t\tr.mu.Unlock()\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tif len(r.sessions) >= maxAgentSessions {\n\t\tr.mu.Unlock()\n\t\treturn fmt.Errorf(\"agent session limit reached: %d\", maxAgentSessions)\n\t}\n\tr.mu.Unlock()\n\n\truntime, key, err := r.acquireRuntime(cp)\n\tif err != nil {\n\t\treturn err\n\t}\n\ts := newServer(runtime, cp)\n\tif err := s.validateConnection(); err != nil {\n\t\tr.releaseRuntime(key)\n\t\treturn err\n\t}\n\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tif _, exists := r.sessions[id]; exists {\n\t\tr.releaseRuntime(key)\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/cassandra-go/main.go#L228-L264","documentation":"openSession caps the number of concurrent agent sessions at maxAgentSessions. When the number of live sessions has reached that limit, new sessions are rejected with this error until existing ones are closed. The check happens while holding r.mu, so it is a reliable upper bound.","triggerScenarios":"openSession called when len(r.sessions) >= maxAgentSessions — i.e. the maximum number of concurrent sessions is already open and none has been closed.","commonSituations":"Long-lived sessions leaked by clients that never call close/disconnect; a burst of connects from scaled-out workers; automated tests opening sessions without cleanup in teardown.","solutions":["Close idle/finished sessions via the disconnect/close RPC to free capacity, then retry.","Add a retry with backoff waiting for session slots to free up.","Audit the client for leaked sessions (connect without close on error paths).","Raise maxAgentSessions if the workload legitimately requires more concurrent sessions."],"exampleFix":"// before\ndefers: connect(...) // error paths never call disconnect\n// after\nresp, err := connect(id)\nif err != nil { return err }\ndefer disconnect(id)","handlingStrategy":"retry","validationCode":"if activeSessions() >= maxAgentSessionsKnownByServer {\n    closeIdleSessions()\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"agent session limit reached\") {\n    time.Sleep(backoff)\n    return retryConnect()\n}","preventionTips":["Close sessions deterministically with defer/finally.","Pool and reuse sessions across workers instead of one per request.","Monitor live session count and alert before hitting the cap."],"tags":["session","limit","resource-exhaustion"],"backgroundTag":"session-limit-reached","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}