gofr-dev/gofr · error
invalid interval, require a value greater than 1 second
Error message
invalid interval, require a value greater than 1 second
What it means
errInvalidInterval is returned by NewOAuthProvider in GoFr's OAuth middleware when the configured key-refresh interval is less than or equal to 1 second. The JWKS key cache requires a refresh interval greater than one second to avoid hammering the identity provider. Construction fails fast with this descriptive error.
Source
Thrown at pkg/gofr/http/middleware/oauth.go:23
"crypto/rsa"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"math/big"
"net/http"
"regexp"
"strings"
"sync"
"time"
"github.com/golang-jwt/jwt/v5"
)
var (
errEmptyProvider = errors.New("require non-empty provider")
errInvalidInterval = errors.New("invalid interval, require a value greater than 1 second")
errEmptyModulus = errors.New("modulus is empty")
errEmptyPublicExponent = errors.New("public exponent is empty")
errEmptyResponseBody = errors.New("response body is empty")
errInvalidURL = errors.New("invalid URL")
)
const jwtRegexPattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+$"
// PublicKeys stores a map of public keys identified by their key ID (kid).
type PublicKeys struct {
mu sync.RWMutex
keys map[string]*rsa.PublicKey
}
// JWKNotFound is an error type indicating a missing JSON Web Key Set (JWKS).
type JWKNotFound struct {
}
View on GitHub (pinned to 187eb24962)
Solutions
- Pass an interval greater than 1 second, e.g. 5 * time.Minute
- Check the config parsing so the value's unit matches expectations (seconds vs ms)
- Ensure the duration variable is actually initialized, not left at its zero value
- Use a sane default (e.g. 15 * time.Minute) when config is absent
Example fix
// before
interval := time.Duration(cfg.Refresh) // cfg.Refresh=0 -> errInvalidInterval
// after
interval := time.Duration(cfg.Refresh) * time.Second
if interval <= time.Second { interval = 15 * time.Minute }
oauth, err := middleware.NewOAuthProvider(provider, interval) Defensive patterns
Strategy: validation
Validate before calling
interval := cfg.RefreshInterval
if interval <= time.Second {
return fmt.Errorf("oauth refresh interval must be > 1s, got %v", interval)
} Type guard
func intervalValid(d time.Duration) bool { return d > time.Second } Try / catch
oauth, err := middleware.NewOAuthProvider(provider, interval)
if err != nil {
if errors.Is(err, middleware.ErrInvalidInterval) {
log.Fatalf("invalid key refresh interval %v: must exceed 1s", interval)
}
return err
} Prevention
- Store durations in config with explicit units (e.g. Go duration strings like "5m")
- Apply a default interval when config is absent or zero
- Sanity-check duration parsing in unit tests
- Avoid sentinel zero values meaning 'disable refresh'
When it happens
Trigger: Calling NewOAuthProvider(provider, d) with d <= 1s (e.g. 0, negative durations, or exactly 1 * time.Second).
Common situations: Refresh interval read from config where the unit was misinterpreted (seconds vs milliseconds producing 0), a zero-valued duration variable never assigned, or an attempt to disable refresh by setting 0.
Related errors
- require non-empty provider
- modulus is empty
- api keys list is empty
- validate func is empty
- user list is empty
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/755ea4e4c87283e7.
Report an issue: GitHub.