{"record":{"id":"c79350fa5f57a5e2","repo":"juicedata/juicefs","slug":"corrupted-session-info-json-error-s-c79350","errorCode":null,"errorMessage":"corrupted session info; json error: %s","messagePattern":"corrupted session info; json error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":839,"sourceCode":"\tvar s Session\n\tvar info []byte\n\tswitch row := row.(type) {\n\tcase *session2:\n\t\ts.Sid = row.Sid\n\t\ts.Expire = time.Unix(row.Expire, 0)\n\t\tinfo = row.Info\n\tcase *session:\n\t\ts.Sid = row.Sid\n\t\ts.Expire = time.Unix(row.Heartbeat, 0).Add(time.Minute * 5)\n\t\tinfo = row.Info\n\t\tif info == nil { // legacy client has no info\n\t\t\tinfo = []byte(\"{}\")\n\t\t}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid type: %T\", row)\n\t}\n\tif err := json.Unmarshal(info, &s); err != nil {\n\t\treturn nil, fmt.Errorf(\"corrupted session info; json error: %s\", err)\n\t}\n\tif detail {\n\t\tvar (\n\t\t\tsrows []sustained\n\t\t\tfrows []flock\n\t\t\tprows []plock\n\t\t)\n\t\terr := m.roTxn(Background(), func(ses *xorm.Session) error {\n\t\t\tif err := ses.Find(&srows, &sustained{Sid: s.Sid}); err != nil {\n\t\t\t\treturn fmt.Errorf(\"find sustained %d: %s\", s.Sid, err)\n\t\t\t}\n\t\t\ts.Sustained = make([]Ino, 0, len(srows))\n\t\t\tfor _, srow := range srows {\n\t\t\t\ts.Sustained = append(s.Sustained, srow.Inode)\n\t\t\t}\n\n\t\t\tif err := ses.Find(&frows, &flock{Sid: s.Sid}); err != nil {\n\t\t\t\treturn fmt.Errorf(\"find flock %d: %s\", s.Sid, err)","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L821-L857","documentation":"Thrown by dbMeta.getSession when the session's serialized `info` JSON column cannot be unmarshalled into a Session. The info column holds client metadata (hostname, IPs, process, mountpoint) written as JSON at session creation; if it is corrupt or not valid JSON matching the Session schema, GetSession/FindSession fails for that session.","triggerScenarios":"`juicefs status <meta-url>` or `juicefs info` listing sessions where a row's info column was truncated, manually edited, written by a client with a legacy nil-info column containing garbage, or corrupted by a DB incident/partial backup restore.","commonSituations":"Restoring a database backup mid-write; manual DB surgery on the session table; very old clients (pre-info schema) combined with corrupted rows; disk-level corruption on self-hosted MySQL/SQLite.","solutions":["Check the offending row: `SELECT sid, info FROM jfs_session2 WHERE sid=<id>` and fix or delete it if it is stale.","If the session is dead, run `juicefs gc --delete` or wait for stale-session cleanup (doCleanStaleSession) to remove the row.","If rows were corrupted by a restore, re-run session info writers by remounting clients.","For SQLite, run integrity_check; for MySQL, check table corruption and repair."],"exampleFix":"// before: SELECT info shows truncated JSON: '{\"ip\":[\"10.0.0', unmarshal fails\n// after: remove stale/corrupt row, then re-query\nDELETE FROM jfs_session2 WHERE sid = 42;\njuicefs status sqlite3://test.db","handlingStrategy":"validation","validationCode":"// pre-validate a session's info JSON before inspecting status output\nvar probe map[string]interface{}\nif err := json.Unmarshal(info, &probe); err != nil {\n    log.Printf(\"session info corrupt, treat session as stale: %v\", err)\n}","typeGuard":"func validSessionInfo(info []byte) bool {\n    var s map[string]interface{}\n    return json.Unmarshal(info, &s) == nil\n}","tryCatchPattern":"s, err := m.GetSession(sid, false)\nif err != nil && strings.Contains(err.Error(), \"corrupted session info\") {\n    logger.Warnf(\"skipping corrupt session %d: %v\", sid, err) // treat as stale, allow cleanup\n    return nil\n}","preventionTips":["Never hand-edit the session table's info column.","Restore DB backups quiesced (no active writers) to avoid torn JSON rows.","Periodically run `juicefs status` and investigate sessions that fail to render."],"tags":["json","metadata","corruption","session"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}