{"record":{"id":"c7d30ebdf2017f93","repo":"nats-io/nats-server","slug":"max-deliver-must-be-set-to-1","errorCode":null,"errorMessage":"max_deliver must be set to -1","messagePattern":"max_deliver must be set to -1","errorType":"validation","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"server/consumer.go","lineNumber":615,"sourceCode":"\tJsAckWaitDefault = 30 * time.Second\n\t// JsDeleteWaitTimeDefault is the default amount of time we will wait for non-durable\n\t// consumers to be in an inactive state before deleting them.\n\tJsDeleteWaitTimeDefault = 5 * time.Second\n\t// JsFlowControlMaxPending specifies default pending bytes during flow control that can be outstanding.\n\tJsFlowControlMaxPending = 32 * 1024 * 1024\n\t// JsDefaultMaxAckPending is set for consumers with explicit ack that do not set the max ack pending.\n\tJsDefaultMaxAckPending = 1000\n\t// JsDefaultPinnedTTL is the default grace period for the pinned consumer to send a new request before a new pin\n\t// is picked by a server.\n\tJsDefaultPinnedTTL = 2 * time.Minute\n)\n\n// Helper function to set consumer config defaults from above.\nfunc setConsumerConfigDefaults(config *ConsumerConfig, streamCfg *StreamConfig, lim *JSLimitOpts, accLim *JetStreamAccountLimits, pedantic bool) *ApiError {\n\t// Setup default of -1, meaning no limit for MaxDeliver.\n\tif config.MaxDeliver == 0 || config.MaxDeliver < -1 {\n\t\tif pedantic && config.MaxDeliver < -1 {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_deliver must be set to -1\"))\n\t\t}\n\t\tconfig.MaxDeliver = -1\n\t}\n\t// Setup zero defaults.\n\tif config.MaxWaiting < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_waiting must not be negative\"))\n\t\t}\n\t\tconfig.MaxWaiting = 0\n\t}\n\tif config.MaxAckPending < -1 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_ack_pending must be set to -1\"))\n\t\t}\n\t\tconfig.MaxAckPending = -1\n\t}\n\tif config.MaxRequestBatch < 0 {\n\t\tif pedantic {","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/consumer.go#L597-L633","documentation":"Consumer config validation in setConsumerConfigDefaults: MaxDeliver was set below -1 (e.g. -5). Only 0 (treated as unlimited, coerced to -1) and values >= -1 are legal; with pedantic mode enabled, MaxDeliver < -1 is rejected instead of silently coerced.","triggerScenarios":"Thrown at server/consumer.go:615 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set max_deliver to -1 for unlimited deliveries or to a positive integer","Omit the field to accept the default","Disable pedantic mode only if silent coercion is acceptable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}