{"record":{"id":"6d3d0f6b9fee6395","repo":"valyala/fasthttp","slug":"fasthttp-no-available-clients","errorCode":null,"errorMessage":"fasthttp: no available clients","messagePattern":"fasthttp: no available clients","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lbclient.go","lineNumber":12,"sourceCode":"package fasthttp\n\nimport (\n\t\"errors\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"time\"\n)\n\n// ErrNoAvailableClients is returned by LBClient methods when no clients are\n// available, for example after every client has been removed.\nvar ErrNoAvailableClients = errors.New(\"fasthttp: no available clients\")\n\n// BalancingClient is the interface for clients, which may be passed\n// to LBClient.Clients.\ntype BalancingClient interface {\n\tDoDeadline(req *Request, resp *Response, deadline time.Time) error\n\tPendingRequests() int\n}\n\n// LBClient balances requests among available LBClient.Clients.\n//\n// It has the following features:\n//\n//   - Balances load among available clients using 'least loaded' + 'least total'\n//     hybrid technique.\n//   - Dynamically decreases load on unhealthy clients.\n//\n// It is forbidden copying LBClient instances. Create new instances instead.\n//","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/lbclient.go#L1-L30","documentation":"LBClient balances requests across a set of BalancingClients. If that set is empty — typically because every client was removed via LBClient.RemoveClient or none were ever added — its Do/DoDeadline/DoTimeout methods return ErrNoAvailableClients instead of panicking or blocking.","triggerScenarios":"Calling LBClient.Do/DoDeadline/DoTimeout after all clients have been removed (RemoveClient called for each), or constructing an LBClient with no Clients configured.","commonSituations":"Health-based removal logic that evicts all backends during an outage; misconfigured service discovery returning an empty backend list; tests constructing LBClient without clients.","solutions":["Ensure at least one BalancingClient is registered before serving traffic: lbClient.Clients = []fasthttp.BalancingClient{c1, c2}.","Guard removal logic so the last healthy client is never removed (e.g. keep a minimum pool size or re-add on failure detection).","Check the error and fall back to a default upstream or return 503 until discovery repopulates clients."],"exampleFix":"// before\nlb := &fasthttp.LBClient{}\nlb.RemoveClient(c1)\nerr := lb.Do(req, resp) // fasthttp: no available clients\n// after\nlb := &fasthttp.LBClient{Clients: []fasthttp.BalancingClient{c1, c2}}\n// never remove the last client:\nif len(lb.Clients) > 1 { lb.RemoveClient(c2) }\nerr := lb.Do(req, resp)","handlingStrategy":"fallback","validationCode":"if lbClient == nil || len(lbClient.Clients) == 0 {\n    return errors.New(\"LBClient has no upstream clients configured\")\n}","typeGuard":null,"tryCatchPattern":"err := lbClient.Do(req, resp)\nif errors.Is(err, fasthttp.ErrNoAvailableClients) {\n    return errNoUpstream // surface 503 / use fallback upstream\n}","preventionTips":["Initialize LBClient.Clients before serving.","Make removal logic refuse to evict the last client.","Re-add clients automatically when health checks recover."],"tags":["load-balancing","client-pool","configuration"],"backgroundTag":"no-available-upstream","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}