Repository navigation
Description
Checklist
- I have checked the issues list
for similar or identical feature requests. - I have checked the pull requests list
for existing proposed implementations of this feature. - I have checked the commit log
to find out if the same feature was already implemented in the
main branch. - I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway).
Related Issues and Possible Duplicates
Related Issues
- None
Possible Duplicates
- None
Brief Summary
Celery's Redis backend does not provide a way to configure additional exceptions that should be treated as connection errors and trigger reconnection. This is needed for handling failover scenarios in Redis-compatible databases (e.g., Dragonfly) where redis.exceptions.ReadOnlyError is raised when a worker still has a TCP connection to a demoted replica.
Use case: We use Dragonfly (Redis-compatible database) in a master-replica setup. During failover:
- The master fails or is demoted
- A replica is promoted to become the new master
- Celery workers still have TCP connections to the old replica (now demoted)
- Write operations raise
redis.exceptions.ReadOnlyError - Celery treats this as a regular exception, not a connection error, so tasks fail instead of retrying with a fresh connection
Design
Architectural Considerations
The RedisBackend class uses a connection_errors tuple to determine which exceptions trigger retry logic in ensure() and exception_safe_to_retry(). Additionally, the ResultConsumer class caches this tuple during __init__, so any modification must update both places.
Proposed Behavior
When a configured exception (e.g., ReadOnlyError) is raised during a Redis operation:
- The exception is recognized as a connection error
- The current connection is disconnected
- Fresh DNS resolution occurs
- A new connection is established (connecting to the new master after failover)
- The operation is retried
This matches the behavior that can be configured i.e. redis-py via retry_on_error=[ReadOnlyError] parameter.
Proposed UI/UX
Option 1: Transport option for additional connection errors
result_backend_transport_options = {
"additional_connection_errors": ["redis.exceptions.ReadOnlyError"],
}
broker_transport_options = {
"additional_connection_errors": ["redis.exceptions.ReadOnlyError"],
}Option 2: Include ReadOnlyError in connection_errors by default
Since ReadOnlyError typically indicates a failover scenario where reconnection is the correct action, it could be included in the default connection_errors tuple.
Diagrams
N/A
Alternatives
Current workaround: Custom backend
We implemented a custom backend that adds ReadOnlyError to connection_errors:
from celery.backends.redis import RedisBackend
from redis import exceptions as redis_exceptions
class RedisBackendReconnectOnReadOnlyError(RedisBackend):
"""Custom Redis backend that treats ReadOnlyError as a connection error."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Add ReadOnlyError to connection_errors tuple.
self.connection_errors = self.connection_errors + (
redis_exceptions.ReadOnlyError,
)
# IMPORTANT: result_consumer copies connection_errors during __init__.
# We must update its copy as well.
self.result_consumer._connection_errors = self.connection_errorsRegistered via:
override_backends = {
"redis": "myapp.celery.backends.redis:RedisBackendReconnectOnReadOnlyError",
"rediss": "myapp.celery.backends.redis:RedisBackendReconnectOnReadOnlyError",
}This workaround is fragile because it relies on the internal _connection_errors attribute of ResultConsumer, which could change in future Celery versions. A built-in solution would be more maintainable.
Activity
xXMrNidaXx commentedon Feb 25, 2026
Supporting ReadOnlyError for Redis failover scenarios is important!
Current workaround:
Better - custom transport:
For Redis Sentinel/Cluster:
+1 for making this configurable in core!
🔧 Building distributed systems? We're hiring at RevolutionAI:
https://www.revolutionai.io/find-work
Production AI projects • Great rates 💼
auvipy commentedon Mar 1, 2026
contributions are welcome
abdullahmujahidali commentedon Mar 1, 2026
I'd like to work on this