juicedata/juicefs · error

find flock %d: %s

Error message

find flock %d: %s

What it means

Thrown by dbMeta.getSession (detail mode) when the SELECT of `flock` rows (POSIX OFD/file locks held by the session) fails. Same aggregation path as the sustained/flock/plock detail queries in GetSession(detail=true).

Source

Thrown at pkg/meta/sql.go:857

		return nil, fmt.Errorf("corrupted session info; json error: %s", err)
	}
	if detail {
		var (
			srows []sustained
			frows []flock
			prows []plock
		)
		err := m.roTxn(Background(), func(ses *xorm.Session) error {
			if err := ses.Find(&srows, &sustained{Sid: s.Sid}); err != nil {
				return fmt.Errorf("find sustained %d: %s", s.Sid, err)
			}
			s.Sustained = make([]Ino, 0, len(srows))
			for _, srow := range srows {
				s.Sustained = append(s.Sustained, srow.Inode)
			}

			if err := ses.Find(&frows, &flock{Sid: s.Sid}); err != nil {
				return fmt.Errorf("find flock %d: %s", s.Sid, err)
			}
			s.Flocks = make([]Flock, 0, len(frows))
			for _, frow := range frows {
				s.Flocks = append(s.Flocks, Flock{frow.Inode, uint64(frow.Owner), string(frow.Ltype)})
			}

			if err := ses.Find(&prows, &plock{Sid: s.Sid}); err != nil {
				return fmt.Errorf("find plock %d: %s", s.Sid, err)
			}
			s.Plocks = make([]Plock, 0, len(prows))
			for _, prow := range prows {
				s.Plocks = append(s.Plocks, Plock{prow.Inode, uint64(prow.Owner), loadLocks(prow.Records)})
			}
			return nil
		})
		if err != nil {
			return nil, err
		}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Inspect the wrapped %s driver error and fix the root cause (connectivity, table integrity).
  2. Confirm the flock table exists with expected columns; run schema checks for the volume's DB.
  3. Retry the session-detail command after the DB is healthy.

Example fix

// before: "find flock 42: driver: bad connection"
// after: reconnect and re-run
mysqladmin -h dbhost ping && juicefs status mysql://...
Defensive patterns

Strategy: retry

Validate before calling

if _, err := x.QueryString("SELECT 1 FROM flock LIMIT 1"); err != nil {
    return fmt.Errorf("flock table unreadable: %w", err)
}

Try / catch

if err != nil && strings.Contains(err.Error(), "find flock") {
    if dbErr := reconnect(); dbErr != nil { return dbErr }
    s, err = m.GetSession(sid, true)
}

Prevention

When it happens

Trigger: Session-detail listing while the flock table is missing, corrupted, or the read transaction errors (connection reset, timeout, deadlock). Not related to lock conflicts — purely a SQL read failure.

Common situations: Partially migrated schema after client version mix; MySQL 'server has gone away' during `juicefs status` on a busy volume; SQLite file corruption.

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/a24d4f02692b379e. Report an issue: GitHub.