{"record":{"id":"0475c67723c85ef5","repo":"caddyserver/caddy","slug":"choose-must-be-at-least-2","errorCode":null,"errorMessage":"choose must be at least 2","messagePattern":"choose must be at least 2","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/reverseproxy/selectionpolicies.go","lineNumber":228,"sourceCode":"\tif err != nil {\n\t\treturn d.Errf(\"invalid choice value '%s': %v\", chooseStr, err)\n\t}\n\tr.Choose = choose\n\treturn nil\n}\n\n// Provision sets up r.\nfunc (r *RandomChoiceSelection) Provision(ctx caddy.Context) error {\n\tif r.Choose == 0 {\n\t\tr.Choose = 2\n\t}\n\treturn nil\n}\n\n// Validate ensures that r's configuration is valid.\nfunc (r RandomChoiceSelection) Validate() error {\n\tif r.Choose < 2 {\n\t\treturn fmt.Errorf(\"choose must be at least 2\")\n\t}\n\treturn nil\n}\n\n// Select returns an available host, if any.\nfunc (r RandomChoiceSelection) Select(pool UpstreamPool, _ *http.Request, _ http.ResponseWriter) *Upstream {\n\tk := min(r.Choose, len(pool))\n\n\t// reservoir sampling (Algorithm R) over the available upstreams:\n\t// the first k available upstreams fill the reservoir, then each\n\t// subsequent one replaces a random reservoir entry with probability\n\t// k/n, so every available upstream is sampled uniformly\n\tchoices := make([]*Upstream, 0, k)\n\tvar available int\n\tfor _, upstream := range pool {\n\t\tif !upstream.Available() {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/reverseproxy/selectionpolicies.go#L210-L246","documentation":"Error \"choose must be at least 2\" thrown in caddyserver/caddy.","triggerScenarios":"Thrown at modules/caddyhttp/reverseproxy/selectionpolicies.go:228 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set 'choose' to 2 or greater for the power of two choices selection policy."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}