{"record":{"id":"9edb19e1167fd7f9","repo":"t8y2/dbx","slug":"failed-to-identify-xugu-server-session-found-d-n","errorCode":null,"errorMessage":"failed to identify Xugu server session: found %d new sessions","messagePattern":"failed to identify Xugu server session: found (.+?) new sessions","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agents/drivers/xugu/main.go","lineNumber":1465,"sourceCode":"\tdefer rows.Close()\n\tresult := map[xuguDatabaseSession]struct{}{}\n\tfor rows.Next() {\n\t\tvar session xuguDatabaseSession\n\t\tif err := rows.Scan(&session.nodeID, &session.sessionID); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tresult[session] = struct{}{}\n\t}\n\treturn result, rows.Err()\n}\n\nfunc newXuguDatabaseSession(\n\tbefore map[xuguDatabaseSession]struct{},\n\tafter map[xuguDatabaseSession]struct{},\n) (xuguDatabaseSession, error) {\n\tsession, n, ok := controlSessionFromSnapshot(before, after)\n\tif !ok {\n\t\treturn xuguDatabaseSession{}, fmt.Errorf(\"failed to identify Xugu server session: found %d new sessions\", n)\n\t}\n\treturn session, nil\n}\n\n// controlSessionFromSnapshot returns the single newly appeared session, if any.\n// Callers treat ok=false as a soft degrade signal (no cancel/kill), not a hard error.\n// n is the number of newly appeared sessions (useful for error messages).\nfunc controlSessionFromSnapshot(\n\tbefore map[xuguDatabaseSession]struct{},\n\tafter map[xuguDatabaseSession]struct{},\n) (xuguDatabaseSession, int, bool) {\n\tvar candidates []xuguDatabaseSession\n\tfor session := range after {\n\t\tif _, existed := before[session]; !existed {\n\t\t\tcandidates = append(candidates, session)\n\t\t}\n\t}\n\tif len(candidates) != 1 {","sourceCodeStart":1447,"sourceCodeEnd":1483,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/xugu/main.go#L1447-L1483","documentation":"When connecting with a control session, the driver snapshots SYS_SESSIONS before and after connecting to identify which new server session belongs to this logical session. newXuguDatabaseSession fails with 'failed to identify Xugu server session: found %d new sessions' when the diff does not yield exactly one new session (zero, or two or more). Callers treat this as a soft degrade: the connection still works, but cancel/kill targeting of that specific server session is unavailable.","triggerScenarios":"Another client connected concurrently between the before/after snapshots (2+ new rows); no new session was visible at all (0 new); the server/driver combination does not support the APP_NAME-based session marking used for identification (some Xugu versions close the socket when APP_NAME is set).","commonSituations":"Busy production Xugu server where other apps open sessions in the same window; older Xugu server/driver combos incompatible with the APP_NAME marker; monitoring tools polling sessions during connect.","solutions":["Retry the connect during a quieter window so the snapshot diff yields exactly one session.","Reduce concurrent connect attempts to this server while using control sessions.","Verify the Xugu server version supports APP_NAME-based identification and SYS_SESSIONS filtering; upgrade or disable the marker if not.","Accept degraded behavior: the session works, only cancel/kill is unavailable — log and continue."],"exampleFix":"// before\nsess, err := newXuguDatabaseSession(before, after) // hard-fails pipelines\nif err != nil { return err }\n// after\nsess, err := newXuguDatabaseSession(before, after)\nif err != nil { log.Warn(\"cancel/kill unavailable: \", err) /* continue degraded */ }","handlingStrategy":"fallback","validationCode":"// avoid noisy snapshot windows: defer connect when other clients are opening sessions\nif serverBusyWindow() { scheduleConnectLater() }","typeGuard":"func isSessionIdentificationError(err error) bool {\n  return err != nil && strings.Contains(err.Error(), \"failed to identify Xugu server session\")\n}","tryCatchPattern":"if err := connectWithControl(); err != nil {\n  if isSessionIdentificationError(err) {\n    log.Warn(\"cancel/kill unavailable; continuing degraded\")\n    proceedWithoutControl()\n  }\n}","preventionTips":["Handle this as a soft failure: session works, cancel/kill is degraded.","Serialize connect attempts when control-session identification matters.","Verify server version supports APP_NAME-based session identification.","Log the 'found N new sessions' counts to diagnose chronically noisy windows."],"tags":["session-identification","snapshot-diff","degraded","xugu"],"backgroundTag":"session-identification-failed","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"}