ipfs/kubo · error

cannot access config, repo not open

Error message

cannot access config, repo not open

What it means

FSRepo.Config returns this when the repo is not open (r.closed is true). Config is an in-memory accessor valid only while the repo is open, so access before Open or after Close fails. The library deliberately refuses instead of returning a zero config.

Source

Thrown at repo/fsrepo/fsrepo.go:587

	r.closed = true
	return r.lockfile.Close()
}

// Config the current config. This function DOES NOT copy the config. The caller
// MUST NOT modify it without first calling `Clone`.
//
// Result when not Open is undefined. The method may panic if it pleases.
func (r *FSRepo) Config() (*config.Config, error) {
	// It is not necessary to hold the package lock since the repo is in an
	// opened state. The package lock is _not_ meant to ensure that the repo is
	// thread-safe. The package lock is only meant to guard against removal and
	// coordinate the lockfile. However, we provide thread-safety to keep
	// things simple.
	packageLock.Lock()
	defer packageLock.Unlock()

	if r.closed {
		return nil, errors.New("cannot access config, repo not open")
	}
	return r.config, nil
}

func (r *FSRepo) UserResourceOverrides() (rcmgr.PartialLimitConfig, error) {
	// It is not necessary to hold the package lock since the repo is in an
	// opened state. The package lock is _not_ meant to ensure that the repo is
	// thread-safe. The package lock is only meant to guard against removal and
	// coordinate the lockfile. However, we provide thread-safety to keep
	// things simple.
	packageLock.Lock()
	defer packageLock.Unlock()

	if r.closed {
		return rcmgr.PartialLimitConfig{}, errors.New("cannot access config, repo not open")
	}
	return r.userResourceOverrides, nil
}

View on GitHub (pinned to 329838acdf)

Solutions

  1. Ensure Open() succeeded before accessing Config
  2. Reorder shutdown so config reads happen before Close
  3. Keep a reference to the config value obtained while open instead of reading post-close

Example fix

// before
repo.Close()
cfg, err := repo.Config()
// after
cfg, err := repo.Config()
if err != nil { return err }
repo.Close()
Defensive patterns

Strategy: validation

Validate before calling

if repoClosed { return errors.New("repo not open") }
cfg, err := repo.Config()

Try / catch

cfg, err := repo.Config()
if err != nil && strings.Contains(err.Error(), "repo not open") {
    // reopen the repo or load config from disk instead
}

Prevention

When it happens

Trigger: Calling Config() before Init/Open, or after Close(); holding a stale FSRepo pointer after the node has shut down; calling Config from a goroutine that outlives repo shutdown.

Common situations: Plugins or hooks reading config during daemon teardown; tests that close the repo at the top of a helper then read config; using a repo instance recreated by migrations after the old one was closed.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/acb3f7c23ea6264a. Report an issue: GitHub.