{"record":{"id":"37cc648e1f7f7da8","repo":"redis/jedis","slug":"no-connections-available-from-connection-provider","errorCode":null,"errorMessage":"No connections available from connection provider","messagePattern":"No connections available from connection provider","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/search/aggr/AggregateIterator.java","lineNumber":92,"sourceCode":"   * Creates a new AggregateIterator.\n   * @param connectionProvider the connection provider for cluster/standalone Redis\n   * @param indexName the search index name\n   * @param aggregationBuilder the aggregation query with cursor configuration\n   * @throws IllegalArgumentException if aggregation doesn't have cursor configured\n   */\n  public AggregateIterator(ConnectionProvider connectionProvider, String indexName,\n      AggregationBuilder aggregationBuilder) {\n    if (!aggregationBuilder.isWithCursor()) {\n      throw new IllegalArgumentException(\"AggregationBuilder must have cursor configured\");\n    }\n\n    this.indexName = indexName;\n    this.batchSize = aggregationBuilder.getCursorCount();\n\n    // Get connection pool entry - use getPrimaryNodesConnectionMap() to get pool-based connections\n    Map<?, ?> connectionMap = connectionProvider.getPrimaryNodesConnectionMap();\n    if (connectionMap.isEmpty()) {\n      throw new JedisException(\"No connections available from connection provider\");\n    }\n    // Randomly select an entry from the map to distribute load across shards\n    List<? extends Map.Entry<?, ?>> entries = new ArrayList<>(connectionMap.entrySet());\n    this.connectionEntry = entries.get(ThreadLocalRandom.current().nextInt(entries.size()));\n\n    // Execute initial aggregation command\n    initializeAggregation(aggregationBuilder);\n  }\n\n  @Override\n  public boolean hasNext() {\n    return aggrCommandResult != null || cursorId != null && cursorId > 0;\n  }\n\n  @Override\n  public AggregationResult next() {\n    if (!hasNext()) {\n      throw new NoSuchElementException(\"No more aggregation results available\");","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/search/aggr/AggregateIterator.java#L74-L110","documentation":"Thrown by the AggregateIterator constructor when the ConnectionProvider's primary-nodes connection map is empty, meaning there is no shard connection available to run the FT.AGGREGATE command. The library cannot route the aggregation without at least one pooled or direct connection entry, so it fails fast during initialization instead of failing later inside next().","triggerScenarios":"Creating a new AggregateIterator (e.g. via a search/aggregation iteration API) while the underlying ConnectionProvider has no primary node connections registered — e.g. the provider was built with an empty node list, all nodes were removed, or the provider is not cluster/pool-backed as expected.","commonSituations":"Misconfigured JedisCluster or provider built without nodes; cluster topology discovered as empty (all masters down or excluded); calling aggregation before the client has connected to any shard; constructing AggregateIterator manually with a stubbed or miswired ConnectionProvider in tests.","solutions":["Check how the ConnectionProvider is built and ensure at least one primary node/pool is configured before creating the iterator","Verify cluster/sentinel topology is reachable and nodes are discovered (check host/port and startup_nodes config)","Confirm you are using the correct provider type for your deployment (cluster provider for cluster mode, not a bare/single provider with no nodes)","Wrap iterator construction in try-catch for JedisException and surface a clear configuration error to the caller"],"exampleFix":"// before\nAggregateIterator it = new AggregateIterator(providerWithNoNodes, \"idx\", aggr); // JedisException\n// after\nMap<?, ?> connMap = provider.getPrimaryNodesConnectionMap();\nif (connMap.isEmpty()) {\n  throw new IllegalStateException(\"Configure at least one Redis node before running aggregations\");\n}\nAggregateIterator it = new AggregateIterator(provider, \"idx\", aggr);","handlingStrategy":"validation","validationCode":"Map<?, ?> connMap = connectionProvider.getPrimaryNodesConnectionMap();\nif (connMap == null || connMap.isEmpty()) {\n  throw new IllegalStateException(\"ConnectionProvider has no primary node connections; check client/node configuration\");\n}","typeGuard":"boolean hasConnections(ConnectionProvider p) {\n  Map<?, ?> m = p.getPrimaryNodesConnectionMap();\n  return m != null && !m.isEmpty();\n}","tryCatchPattern":"try {\n  AggregateIterator it = new AggregateIterator(provider, indexName, aggr);\n} catch (JedisException e) {\n  // no connections available — fix provider config before retrying\n  throw new ConfigurationException(\"No Redis nodes configured for aggregation\", e);\n}","preventionTips":["Always configure at least one primary node/pool before running aggregations","Validate cluster discovery yields nodes (log the primary-nodes map size at startup)","Use the builder-based clients so provider wiring is validated at build() time","In tests, never stub getPrimaryNodesConnectionMap() with an empty map"],"tags":["jedis","search","aggregation","connection-provider","initialization"],"backgroundTag":"empty-result-set","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}