{"record":{"id":"f85183a0d70ecf57","repo":"juicedata/juicefs","slug":"insert-new-session-d-s","errorCode":null,"errorMessage":"insert new session %d: %s","messagePattern":"insert new session (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":813,"sourceCode":"\t\t\t\tif err := mustInsert(s, &beans); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tm.genLog(Background(), s, time.Now().UnixNano(), \"NEWSESSION(%d,%d,%s)\", m.sid, beans.Expire, logEncode(sinfo))\n\t\t\t\treturn nil\n\t\t\t}); err == nil {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tif isDuplicateEntryErr(err) {\n\t\t\t\tlogger.Warnf(\"session id %d is already used\", m.sid)\n\t\t\t\tif v, e := m.incrCounter(\"nextSession\", 1); e == nil {\n\t\t\t\t\tm.sid = uint64(v)\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\treturn fmt.Errorf(\"get session ID: %s\", e)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn fmt.Errorf(\"insert new session %d: %s\", m.sid, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (m *dbMeta) getSession(row interface{}, detail bool) (*Session, error) {\n\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","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L795-L831","documentation":"Thrown by the SQL metadata engine (dbMeta) in NewSession when inserting the client's session row into the `jfs.session2` table fails with an error that is NOT a duplicate-entry error. The session id, a counter-based value, and the underlying database error are wrapped in the message. Duplicate sids are retried automatically; any other DB failure is fatal to session registration.","triggerScenarios":"Mounting a JuiceFS volume backed by MySQL/PostgreSQL/SQLite where the INSERT into the session table fails: DB unreachable during mount, connection dropped mid-transaction, table missing/corrupted, transaction aborted, or lock wait timeout. Only non-duplicate errors reach this path (duplicate sid loops with a new id).","commonSituations":"Database restarted or network partitioned between client and metadata DB while a client mounts; max_connections exhausted on MySQL; session2 table dropped or migrated by an incompatible newer client; SQL mode / constraint conflicts after version upgrades.","solutions":["Check connectivity to the metadata database from the mounting client (host, port, credentials, max_connections).","Read the wrapped %s detail to identify the underlying SQL error and fix it (e.g. repair missing session2 table).","Retry the mount once the database is healthy; session registration is idempotent per client.","If it recurs, verify all clients run compatible JuiceFS versions against the same metadata schema."],"exampleFix":"// before: mount fails with \"insert new session 42: driver: bad connection\"\n// after: ensure DB is reachable and retry\n$ mysql -h dbhost -u juicefs -p -e 'SELECT 1'   # verify connectivity\n$ juicefs mount mysql://juicefs@dbhost/myfs /mnt/jfs","handlingStrategy":"retry","validationCode":"// before mounting, verify metadata DB connectivity\nif err := db.Ping(); err != nil {\n    return fmt.Errorf(\"metadata DB unreachable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"for i := 0; i < 3; i++ {\n    err := mount(metaURL, mnt)\n    if err == nil || !strings.Contains(err.Error(), \"insert new session\") {\n        break\n    }\n    time.Sleep(time.Duration(1<<i) * time.Second) // backoff while DB recovers\n}","preventionTips":["Monitor metadata DB health (max_connections, wait_timeout) before mass mounts.","Keep all clients on compatible JuiceFS versions to avoid schema surprises.","Use connection pooling limits that fit the DB's capacity."],"tags":["database","metadata","session","go"],"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-14T05:17:10.506Z"}