{"record":{"id":"419b18120f42c225","repo":"apache/beam","slug":"failed-to-connect-to-host-s-error-s","errorCode":null,"errorMessage":"Failed to connect to host: %s, error: %s","messagePattern":"Failed to connect to host: (.+?), error: (.+?)","errorType":"exception","errorClass":"UserCodeExecutionException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/rrio/src/main/java/org/apache/beam/io/requestresponse/RedisClient.java","lineNumber":183,"sourceCode":"   */\n  void setex(String key, Long value, Duration expiry) throws UserCodeExecutionException {\n    try {\n      getSafeClient().setex(key, expiry.getStandardSeconds(), String.valueOf(value));\n    } catch (JedisException e) {\n      throw new UserCodeExecutionException(e);\n    }\n  }\n\n  /** Overrides {@link SetupTeardown}'s {@link SetupTeardown#setup} method. */\n  @Override\n  public void setup() throws UserCodeExecutionException {\n    try {\n      jedis = new JedisPooled(uri);\n      jedis.ping();\n    } catch (JedisException e) {\n      String message =\n          String.format(\"Failed to connect to host: %s, error: %s\", uri, e.getMessage());\n      throw new UserCodeExecutionException(message, e);\n    }\n  }\n\n  private @NonNull JedisPooled getSafeClient() {\n    return checkStateNotNull(jedis);\n  }\n\n  /** Overrides {@link SetupTeardown}'s {@link SetupTeardown#teardown} method. */\n  @Override\n  public void teardown() throws UserCodeExecutionException {\n    if (jedis != null) {\n      jedis.close();\n    }\n  }\n}\n","sourceCodeStart":165,"sourceCodeEnd":199,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/rrio/src/main/java/org/apache/beam/io/requestresponse/RedisClient.java#L165-L199","documentation":"RedisClient (used by RequestResponseIO's cache) establishes a pooled Jedis connection in setup() and verifies it with ping(). If any JedisException occurs (connect refused, auth error, timeout), it throws UserCodeExecutionException with the URI and underlying message.","triggerScenarios":"RequestResponseIO with a Redis cache where setup() runs and new JedisPooled(uri).ping() throws JedisException.","commonSituations":"Wrong Redis host/port in the URI; Redis requiring auth (no password supplied); TLS mismatch (redis:// vs rediss://); Redis not reachable from worker network (firewall/VPC); Redis maxclients reached.","solutions":["Verify the URI (scheme redis:// or rediss://, correct host, port 6379/6380) and that the worker network can reach it.","Include credentials in the URI (redis://:password@host:port) or use JedisPooled with auth if Redis requires AUTH.","Confirm Redis is running (redis-cli ping from a worker) and check maxclients/timeout settings.","Review the wrapped JedisException message in the error for the exact network/auth cause."],"exampleFix":"// before\nRedisClient.from(uri) // uri = \"redis://localhost:6379\" but Redis needs auth\n// after\nRedisClient.from(URI.create(\"redis://:secretpassword@redis-host:6379\"));","handlingStrategy":"validation","validationCode":"// Pre-flight connectivity check before configuring the cache\nURI uri = URI.create(\"redis://redis-host:6379\");\ntry (JedisPooled j = new JedisPooled(uri)) { j.ping(); } catch (JedisException e) { throw new IllegalStateException(\"Redis unreachable: \" + uri, e); }","typeGuard":null,"tryCatchPattern":"try { RequestResponseIO.of(call, RedisClient.from(uri)); } catch (UserCodeExecutionException e) { if (e.getMessage().startsWith(\"Failed to connect to host\")) { /* fix URI/auth/network then retry */ } }","preventionTips":["Verify redis-cli -h host -p port ping works from a worker node before deploying.","Encode credentials and TLS scheme (rediss://) correctly in the URI.","Open firewall/VPC routes between the Beam workers and Redis.","Monitor Redis maxclients and connection timeouts."],"tags":["redis","connection","cache","apache-beam"],"backgroundTag":"connection-refused","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}