Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6aa87f8

Browse files
authored
Ensure that we never stop reconnecting to redis (#9391)
1 parent 8a33d21 commit 6aa87f8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

changelog.d/9391.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where Synapse would occaisonally stop reconnecting after the connection was lost.

synapse/replication/tcp/redis.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
import logging
1717
from inspect import isawaitable
18-
from typing import TYPE_CHECKING, Optional, Type, cast
18+
from typing import TYPE_CHECKING, Generic, Optional, Type, TypeVar, cast
1919

20+
import attr
2021
import txredisapi
2122

2223
from synapse.logging.context import PreserveLoggingContext, make_deferred_yieldable
@@ -42,6 +43,24 @@
4243

4344
logger = logging.getLogger(__name__)
4445

46+
T = TypeVar("T")
47+
V = TypeVar("V")
48+
49+
50+
@attr.s
51+
class ConstantProperty(Generic[T, V]):
52+
"""A descriptor that returns the given constant, ignoring attempts to set
53+
it.
54+
"""
55+
56+
constant = attr.ib() # type: V
57+
58+
def __get__(self, obj: Optional[T], objtype: Type[T] = None) -> V:
59+
return self.constant
60+
61+
def __set__(self, obj: Optional[T], value: V):
62+
pass
63+
4564

4665
class RedisSubscriber(txredisapi.SubscriberProtocol, AbstractConnection):
4766
"""Connection to redis subscribed to replication stream.
@@ -195,6 +214,10 @@ class SynapseRedisFactory(txredisapi.RedisFactory):
195214
we detect dead connections.
196215
"""
197216

217+
# We want to *always* retry connecting, txredisapi will stop if there is a
218+
# failure during certain operations, e.g. during AUTH.
219+
continueTrying = cast(bool, ConstantProperty(True))
220+
198221
def __init__(
199222
self,
200223
hs: "HomeServer",
@@ -243,7 +266,6 @@ class RedisDirectTcpReplicationClientFactory(SynapseRedisFactory):
243266
"""
244267

245268
maxDelay = 5
246-
continueTrying = True
247269
protocol = RedisSubscriber
248270

249271
def __init__(

0 commit comments

Comments
 (0)