dgraph-io/dgraph · warning
Couldn't Parse max-age
Error message
Couldn't Parse max-age
What it means
ParseMaxAge extracts the max-age value from a Cache-Control header string. If the string contains neither a 'max-age' nor 's-maxage' directive, it returns this error. FetchJWK uses it to cache JSON Web Keys, so it signals the HTTP response had no parseable cache lifetime.
Source
Thrown at graphql/authorization/utils.go:25
import (
"strconv"
"strings"
"time"
"github.com/pkg/errors"
)
func ParseMaxAge(CacheControlHeaderStr string) (int64, error) {
splittedHeaderStr := strings.Split(CacheControlHeaderStr, ",")
for _, str := range splittedHeaderStr {
strTrimSpace := strings.TrimSpace(str)
if strings.HasPrefix(strTrimSpace, "max-age") || strings.HasPrefix(strTrimSpace, "s-maxage") {
maxAge, err := strconv.Atoi(strings.Split(str, "=")[1])
return int64(maxAge), err
}
}
return 0, errors.Errorf("Couldn't Parse max-age")
}
func ParseExpires(ExpiresHeaderStr string) (int64, error) {
expDate, err := time.Parse(time.RFC1123, ExpiresHeaderStr)
if err != nil {
return 0, err
}
currDate := time.Now().Round(time.Second)
diff := expDate.Sub(currDate).Seconds()
return int64(diff), nil
}
View on GitHub (pinned to 759e242be6)
Solutions
- Ensure the JWKS endpoint returns a Cache-Control header with a valid max-age or s-maxage integer
- Add an Expires header as fallback (ParseExpires handles it)
- Return valid cache headers from the identity provider / reverse proxy
- Handle the error in FetchJWK by falling back to a default cache duration
Example fix
// before Cache-Control: no-store // after Cache-Control: public, max-age=3600
Defensive patterns
Strategy: fallback
Validate before calling
const m = cacheControl.match(/(?:s-)?max-age=(\d+)/);
if (!m) console.warn('no max-age in Cache-Control header:', cacheControl); Try / catch
try {
ttl = ParseMaxAge(cacheControl);
} catch (err) {
ttl = defaultJWKCacheTTL; // e.g. 60s
} Prevention
- Configure JWKS endpoints to emit Cache-Control with max-age
- Also supply an Expires header as a secondary source
- Wrap ParseMaxAge with a safe default duration
- Log the raw header when parsing fails for easier diagnosis
When it happens
Trigger: Calling FetchJWK against a JWKS endpoint whose response has a Cache-Control header without max-age/s-maxage, or a header that fails strconv.Atoi on the value after '='.
Common situations: JWKS server sends 'Cache-Control: no-cache' or 'no-store'; malformed header like 'max-age=abc'; header with quotes around the value ('max-age="3600"').
Related errors
- NQuad failed sanity check. Subject: %q, Predicate: %q, Objec
- expected '(', found: %s
- expected variable name, found: %s
- empty variable name in function call
- expected ')', found: %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/7e557aab73b3673f.
Report an issue: GitHub.