nats-io/nats-server · error

Fetch timeout %v is too smal

Error message

Fetch timeout %v is too smal

What it means

Validation error from the FetchTimeout DirResOption: the caller passed a fetch timeout that is zero or negative, which would make account fetch waits meaningless. Note the message has a typo ('smal' instead of 'small').

Source

Thrown at server/accounts.go:4682

		dr.Unlock()
		if srv == nil {
			return _EMPTY_, err
		}
		return srv.fetch(dr, name, to) // lookup from other server
	}
}

func (dr *DirAccResolver) Store(name, jwt string) error {
	return dr.saveIfNewer(name, jwt)
}

type DirResOption func(s *DirAccResolver) error

// limits the amount of time spent waiting for an account fetch to complete
func FetchTimeout(to time.Duration) DirResOption {
	return func(r *DirAccResolver) error {
		if to <= time.Duration(0) {
			return fmt.Errorf("Fetch timeout %v is too smal", to)
		}
		r.fetchTimeout = to
		return nil
	}
}

func (dr *DirAccResolver) apply(opts ...DirResOption) error {
	for _, o := range opts {
		if err := o(dr); err != nil {
			return err
		}
	}
	return nil
}

func NewDirAccResolver(path string, limit int64, syncInterval time.Duration, delete deleteType, opts ...DirResOption) (*DirAccResolver, error) {
	if limit == 0 {
		limit = math.MaxInt64

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Pass a strictly positive duration, e.g. FetchTimeout(2 * time.Second).
  2. Clamp or default the configured value: if cfg <= 0 { cfg = 2 * time.Second } before applying the option.
  3. Fix config parsing so unset values become a sensible default rather than 0.
  4. Ignore the typo in the message — it indicates the duration value, not a different problem.

Example fix

// before
opts = append(opts, FetchTimeout(cfg.FetchTimeout)) // 0 when unset
// after
to := cfg.FetchTimeout
if to <= 0 { to = 2 * time.Second }
opts = append(opts, FetchTimeout(to))
Defensive patterns

Strategy: validation

Validate before calling

to := cfg.FetchTimeout
if to <= 0 {
    return fmt.Errorf("FetchTimeout must be > 0, got %v", to)
}
opts = append(opts, FetchTimeout(to))

Type guard

func validFetchTimeout(d time.Duration) bool { return d > 0 }

Try / catch

if err := FetchTimeout(to)(resolver); err != nil {
    return fmt.Errorf("invalid fetch timeout %v: %w", to, err)
}

Prevention

When it happens

Trigger: Passing FetchTimeout(0) or FetchTimeout(-1s) (any value <= time.Duration(0)) as a DirResOption when constructing a DirAccResolver, e.g. with the WithDirResolver/FetchTimeout option in server options.

Common situations: Programmatic server option construction where the timeout is derived from a config value that is unset (zero value) or parsed incorrectly as negative.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/41bf3c91c550bc82. Report an issue: GitHub.