{"record":{"id":"b60d4b6952982f1e","repo":"nats-io/nats-server","slug":"10052-b60d4b","errorCode":"10052","errorMessage":"counter stream cannot use message TTLs","messagePattern":"counter stream cannot use message TTLs","errorType":"validation","errorClass":"ApiError (JSStreamInvalidConfigF)","httpStatus":500,"severity":"error","filePath":"server/stream.go","lineNumber":1999,"sourceCode":"\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}\n\t\tif cfg.AllowMsgSchedules {\n\t\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"counter stream cannot use message schedules\"))\n\t\t}\n\t\tif cfg.Retention != LimitsPolicy {\n\t\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"counter stream can only use limits retention\"))\n\t\t}\n\t}\n\n\t// Check for new discard new per subject, we require the discard policy to also be new.\n\tif cfg.DiscardNewPer {\n\t\tif cfg.Discard != DiscardNew {\n\t\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"discard new per subject requires discard new policy to be set\"))\n\t\t}\n\t\tif cfg.MaxMsgsPer <= 0 {\n\t\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"discard new per subject requires max msgs per subject > 0\"))\n\t\t}\n\t}","sourceCodeStart":1981,"sourceCodeEnd":2017,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L1981-L2017","documentation":"Counter streams (AllowMsgCounter=true) cannot also enable per-message TTLs (AllowMsgTTL): message-level expiration interferes with counter state consistency, so server/stream.go validation rejects the combination. Returned as a JSStreamInvalidConfigError. The associated code for these newer counter validation errors is 10052 (JSStreamInvalidConfig).","triggerScenarios":"AddStream/UpdateStream with AllowMsgCounter=true and AllowMsgTTL=true, e.g. a stream that both increments counters and sets Nats-Msg-Ttl headers.","commonSituations":"Enabling all modern stream features (counters, msg TTLs, schedules) on one stream from a feature checklist; migrating a stream to counters without auditing existing publishers that send TTL headers.","solutions":["Set AllowMsgTTL=false on the counter stream.","Split workloads: use a separate stream for TTL'd messages, keeping the counter stream TTL-free.","Or drop AllowMsgCounter and implement counters at the application level if TTLs are essential.","Upgrade/align client and server versions and re-check docs, since these are recent JetStream features."],"exampleFix":"// before\n StreamConfig{Name: \"CTR\", AllowMsgCounter: true, AllowMsgTTL: true}\n// after\n StreamConfig{Name: \"CTR\", AllowMsgCounter: true, AllowMsgTTL: false}","handlingStrategy":"validation","validationCode":"if cfg.AllowMsgCounter && cfg.AllowMsgTTL {\n    return fmt.Errorf(\"counter streams cannot enable message TTLs\")\n}","typeGuard":null,"tryCatchPattern":"var scErr *jetstream.JSApiError\nif _, err := js.CreateStream(ctx, cfg); errors.As(err, &scErr) && strings.Contains(scErr.Description, \"counter stream cannot use message TTLs\") {\n    cfg.AllowMsgTTL = false\n    _, err = js.CreateStream(ctx, cfg)\n}","preventionTips":["Audit publishers for Nats-Msg-Ttl headers before enabling AllowMsgCounter.","Split TTL workloads onto a separate stream.","Check the NATS server feature compatibility notes for counters."],"tags":["jetstream","stream-config","counter","msg-ttl","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"}