juicedata/juicefs · error

session not found: %d

Error message

session not found: %d

What it means

Returned by dbMeta.GetSession when no row with the given sid exists in either the current `session2` table or the legacy `session` table. The sid refers to a client session (e.g. from a crash recovery prompt or `juicefs status`) that has since been cleaned up or never existed in this metadata engine.

Source

Thrown at pkg/meta/sql.go:904

			if ok, err = ses.Get(&row); err != nil {
				return err
			} else if ok {
				s, err = m.getSession(&row, detail)
				return err
			}
		}
		if ok, err := ses.IsTableExist(&session{}); err != nil {
			return err
		} else if ok {
			row := session{Sid: sid}
			if ok, err = ses.Get(&row); err != nil {
				return err
			} else if ok {
				s, err = m.getSession(&row, detail)
				return err
			}
		}
		return fmt.Errorf("session not found: %d", sid)
	})
	return
}

func (m *dbMeta) ListSessions() ([]*Session, error) {
	var sessions []*Session
	err := m.roTxn(Background(), func(ses *xorm.Session) error {
		if ok, err := ses.IsTableExist(&session2{}); err != nil {
			return err
		} else if ok {
			var rows []session2
			if err = ses.Find(&rows); err != nil {
				return err
			}
			sessions = make([]*Session, 0, len(rows))
			for i := range rows {
				s, err := m.getSession(&rows[i], false)
				if err != nil {

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Re-run `juicefs status <meta-url>` to list currently live sessions and confirm the sid exists.
  2. If the sid belonged to a dead client, nothing needs recovery — its locks/sustained inodes were already cleaned by stale-session cleanup.
  3. Verify you are querying the same metadata engine URL as the volume the sid came from.

Example fix

// before: juicefs status 42 -> "session not found: 42"
// after: list live sessions first
juicefs status sqlite3://test.db | grep -w 42   # confirm sid is live before querying detail
Defensive patterns

Strategy: validation

Validate before calling

// confirm the sid exists before requesting details
sessions, err := m.ListSessions()
if err != nil { return err }
found := false
for _, s := range sessions { if s.Sid == sid { found = true; break } }
if !found { return fmt.Errorf("sid %d is not live on this volume", sid) }

Try / catch

s, err := m.GetSession(sid, false)
if err != nil && strings.Contains(err.Error(), "session not found") {
    logger.Infof("session %d already cleaned up; no recovery needed", sid)
    return nil
}

Prevention

When it happens

Trigger: `juicefs status <sid>` with a stale sid after the client disconnected and stale-session cleanup removed it; passing a sid from a different volume/metadata URL; typo'd sid; querying before any client has mounted (legacy `session` table absent).

Common situations: Answering 'N) recover / D) delete' prompts from a stale crash dump where the session already exited; copy-pasting sids between dev and prod volumes; cleanup job (juicefs gc / heartbeat expiry) ran between observing and querying the session.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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