juicedata/juicefs · error

get session ID: %s

Error message

get session ID: %s

What it means

When inserting a new session row, a duplicate primary key on the session ID triggers re-allocation via the nextSession counter. If that incrCounter call itself fails, the error is wrapped as 'get session ID: %s' and session creation fails, preventing the mount.

Source

Thrown at pkg/meta/sql.go:810

			})
		} else {
			if err = m.txn(func(s *xorm.Session) error {
				if err := mustInsert(s, &beans); err != nil {
					return err
				}
				m.genLog(Background(), s, time.Now().UnixNano(), "NEWSESSION(%d,%d,%s)", m.sid, beans.Expire, logEncode(sinfo))
				return nil
			}); err == nil {
				break
			}

			if isDuplicateEntryErr(err) {
				logger.Warnf("session id %d is already used", m.sid)
				if v, e := m.incrCounter("nextSession", 1); e == nil {
					m.sid = uint64(v)
					continue
				} else {
					return fmt.Errorf("get session ID: %s", e)
				}
			} else {
				return fmt.Errorf("insert new session %d: %s", m.sid, err)
			}
		}
	}
	return nil
}

func (m *dbMeta) getSession(row interface{}, detail bool) (*Session, error) {
	var s Session
	var info []byte
	switch row := row.(type) {
	case *session2:
		s.Sid = row.Sid
		s.Expire = time.Unix(row.Expire, 0)
		info = row.Info
	case *session:

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Retry the mount — the collision retry usually succeeds once the counter increments
  2. Verify the nextSession counter row exists and is correct (SELECT ... WHERE name='nextSession')
  3. Check DB connectivity and error logs for the wrapped incrCounter failure
  4. If collisions persist after a restored DB, manually fix the nextSession counter above the max session ID
Defensive patterns

Strategy: retry

Validate before calling

// Verify counter sanity after restoring a metadata DB
SELECT MAX(sid) FROM session2; SELECT value FROM setting WHERE name='nextSession';

Try / catch

err := mountWithRetry(sqlURL, 3) // transient incrCounter failures usually clear on retry

Prevention

When it happens

Trigger: Mount with SQL metadata when the generated session ID collides (isDuplicateEntryErr) and the subsequent incrCounter('nextSession', 1) transaction fails — DB connection error, deadlock, or permission failure on the counter row.

Common situations: Restored/copied metadata databases with stale counter values causing repeated SID collisions; transient DB failures exactly during collision retry; counter row deleted or corrupted.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/2643a6bdece04a25. Report an issue: GitHub.