{"record":{"id":"22c53f3b7d94dd86","repo":"juicedata/juicefs","slug":"get-session-id-s","errorCode":null,"errorMessage":"get session ID: %s","messagePattern":"get session ID: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/base.go","lineNumber":796,"sourceCode":"\tctx := m.sessCtx\n\tgo m.refresh(ctx)\n\n\tif err := m.en.cacheACLs(ctx); err != nil {\n\t\treturn err\n\t}\n\n\tif m.conf.ReadOnly {\n\t\tlogger.Infof(\"Create read-only session OK with version: %s\", version.Version())\n\t\treturn nil\n\t}\n\n\tif record {\n\t\t// use the original sid if it's not 0\n\t\taction := \"Update\"\n\t\tif m.sid == 0 {\n\t\t\tv, err := m.en.incrCounter(\"nextSession\", 1)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"get session ID: %s\", err)\n\t\t\t}\n\t\t\tm.sid = uint64(v)\n\t\t\tm.conf.Sid = m.sid\n\t\t\taction = \"Create\"\n\t\t}\n\t\tif err := m.en.doNewSession(m.newSessionInfo(), action == \"Update\"); err != nil {\n\t\t\treturn fmt.Errorf(\"create session: %s\", err)\n\t\t}\n\t\tlogger.Infof(\"%s session %d OK with version: %s\", action, m.sid, version.Version())\n\t}\n\n\tm.loadQuotas()\n\n\tm.sessWG.Add(3)\n\tgo m.flushStats(ctx)\n\tgo m.flushDirStat(ctx)\n\tgo m.flushQuotas(ctx)\n\tm.startDeleteSliceTasks() // start MaxDeletes tasks","sourceCodeStart":778,"sourceCodeEnd":814,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/base.go#L778-L814","documentation":"During NewSession, baseMeta must allocate a session ID by incrementing the `nextSession` counter in the metadata engine; if incrCounter fails, this error wraps the cause. Without a session ID the client cannot register itself, so startup fails.","triggerScenarios":"Metadata engine unreachable or erroring when incrementing nextSession (network partition, Redis READONLY replica, SQL connection failure); corrupted counter value that cannot be incremented.","commonSituations":"Redis in read-only mode or out of memory; MySQL/PostgreSQL connection issues at mount time; transient network blips during mount in Kubernetes environments.","solutions":["Check metadata engine connectivity and health (auth, network, read-only state) and retry the mount","Verify the client has write permission on the metadata engine (counter must be incremented)","Inspect engine logs for the underlying incrCounter error and fix the backend"],"exampleFix":"# before: replica rejects writes\njuicefs mount redis://replica:6379 /jfs\n# after: point at primary\njuicefs mount redis://primary:6379 /jfs","handlingStrategy":"retry","validationCode":"// preflight: ensure the metadata engine accepts writes\n// e.g. redis-cli -h host PING and confirm role:master (not read-only replica)","typeGuard":null,"tryCatchPattern":"if err := meta.NewSession(); err != nil { if strings.Contains(err.Error(), \"get session ID\") { time.Sleep(backoff); retry(meta.NewSession) } }","preventionTips":["Point clients at the primary, not a read-only replica","Monitor metadata backend health before mounts","Use connection retries/keepalives in orchestration"],"tags":["session","metadata","database"],"backgroundTag":"database-write-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}