{"record":{"id":"5bb2c838d81e6226","repo":"nats-io/nats-server","slug":"duplicates-window-can-not-be-larger-then-server-li","errorCode":null,"errorMessage":"duplicates window can not be larger then server limit of %v","messagePattern":"duplicates window can not be larger then server limit of (.+?)","errorType":"error_code","errorClass":"JSStreamInvalidConfigError","httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":1982,"sourceCode":"\t\t}\n\t\tif cfg.MaxAge != 0 && cfg.MaxAge < maxWindow {\n\t\t\tif pedantic {\n\t\t\t\treturn StreamConfig{}, NewJSPedanticError(fmt.Errorf(\"duplicate window cannot be bigger than max age\"))\n\t\t\t}\n\t\t\tcfg.Duplicates = cfg.MaxAge\n\t\t} else {\n\t\t\tcfg.Duplicates = maxWindow\n\t\t}\n\t}\n\tif cfg.Duplicates < 0 {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"duplicates window can not be negative\"))\n\t}\n\t// Check that duplicates is not larger then age if set.\n\tif cfg.MaxAge != 0 && cfg.Duplicates > cfg.MaxAge {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"duplicates window can not be larger then max age\"))\n\t}\n\tif lim.Duplicates > 0 && cfg.Duplicates > lim.Duplicates {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"duplicates window can not be larger then server limit of %v\",\n\t\t\tlim.Duplicates.String()))\n\t}\n\tif cfg.Duplicates > 0 && cfg.Duplicates < 100*time.Millisecond {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"duplicates window needs to be >= 100ms\"))\n\t}\n\n\tif cfg.DenyPurge && cfg.AllowRollup {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"roll-ups require the purge permission\"))\n\t}\n\n\t// Counter is not compatible with some settings.\n\tif cfg.AllowMsgCounter {\n\t\tif cfg.Discard == DiscardNew {\n\t\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"counter stream cannot use discard new\"))\n\t\t}\n\t\tif cfg.AllowMsgTTL {\n\t\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"counter stream cannot use message TTLs\"))\n\t\t}","sourceCodeStart":1964,"sourceCodeEnd":2000,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L1964-L2000","documentation":"If the server (or account/template limits) defines a maximum Duplicates window (lim.Duplicates > 0), validation rejects any configured window larger than that server-side limit. This keeps duplicate-detection caches from growing beyond operational limits imposed via server config, account limits, or stream templates. Returned as a JSStreamInvalidConfigError including the limit value in the message.","triggerScenarios":"AddStream/UpdateStream with StreamConfig.Duplicates exceeding the duplicates limit from JetStreamAccountLimits or StreamLimits (e.g. requesting 10m when the account caps duplicates at 2m).","commonSituations":"Shared/multi-tenant NATS deployments where operators cap duplicate windows per account; deploying an app with a hardcoded large Duplicates value into a cluster with tighter limits than the dev environment.","solutions":["Read the effective limits (AccountInfo / JetStream limits) and clamp Duplicates to the reported limit.","Lower StreamConfig.Duplicates to at or below the server limit shown in the error message.","Ask the operator to raise the duplicates limit in the account limits if a longer window is genuinely needed.","Make Duplicates configurable per environment rather than hardcoded."],"exampleFix":"// before\n StreamConfig{Name: \"ORDERS\", Duplicates: 10 * time.Minute} // account limit: 2m\n// after\n StreamConfig{Name: \"ORDERS\", Duplicates: 2 * time.Minute}","handlingStrategy":"validation","validationCode":"info, err := js.AccountInfo(ctx)\nif err != nil {\n    return err\n}\nif max := info.Limits.StreamLimits.Duplicates; max > 0 && cfg.Duplicates > max {\n    cfg.Duplicates = max\n}","typeGuard":null,"tryCatchPattern":"var scErr *jetstream.JSApiError\nif _, err := js.CreateStream(ctx, cfg); errors.As(err, &scErr) && strings.Contains(scErr.Description, \"duplicates window can not be larger then server limit\") {\n    return fmt.Errorf(\"reduce Duplicates to the account limit: %w\", err)\n}","preventionTips":["Call AccountInfo at startup and clamp Duplicates to StreamLimits.Duplicates.","Make Duplicates configurable per environment instead of hardcoding.","Document account limits when deploying to multi-tenant clusters."],"tags":["jetstream","stream-config","account-limits","nats"],"backgroundTag":"invalid-stream-config","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}