apache/beam · error · UserCodeExecutionException
Failed to connect to host: %s, error: %s
Error message
Failed to connect to host: %s, error: %s
What it means
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.
Source
Thrown at sdks/java/io/rrio/src/main/java/org/apache/beam/io/requestresponse/RedisClient.java:183
*/
void setex(String key, Long value, Duration expiry) throws UserCodeExecutionException {
try {
getSafeClient().setex(key, expiry.getStandardSeconds(), String.valueOf(value));
} catch (JedisException e) {
throw new UserCodeExecutionException(e);
}
}
/** Overrides {@link SetupTeardown}'s {@link SetupTeardown#setup} method. */
@Override
public void setup() throws UserCodeExecutionException {
try {
jedis = new JedisPooled(uri);
jedis.ping();
} catch (JedisException e) {
String message =
String.format("Failed to connect to host: %s, error: %s", uri, e.getMessage());
throw new UserCodeExecutionException(message, e);
}
}
private @NonNull JedisPooled getSafeClient() {
return checkStateNotNull(jedis);
}
/** Overrides {@link SetupTeardown}'s {@link SetupTeardown#teardown} method. */
@Override
public void teardown() throws UserCodeExecutionException {
if (jedis != null) {
jedis.close();
}
}
}
View on GitHub (pinned to 12126d8942)
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.
Example fix
// before
RedisClient.from(uri) // uri = "redis://localhost:6379" but Redis needs auth
// after
RedisClient.from(URI.create("redis://:secretpassword@redis-host:6379")); Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight connectivity check before configuring the cache
URI uri = URI.create("redis://redis-host:6379");
try (JedisPooled j = new JedisPooled(uri)) { j.ping(); } catch (JedisException e) { throw new IllegalStateException("Redis unreachable: " + uri, e); } Try / catch
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 */ } } Prevention
- 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.
When it happens
Trigger: RequestResponseIO with a Redis cache where setup() runs and new JedisPooled(uri).ping() throws JedisException.
Common situations: 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.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- An unsupported type of cache was passed in. Received %s.
- No RabbitMQ channel available
- invalid redis cursor %s
- need request coder to be able to use Cache with RequestRespo
- Failed to import redis. You can ensure it is installed by in
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/419b18120f42c225.
Report an issue: GitHub.