From 8582d0b0852eb7ff5d2fba4841b916d2f41f4dfa Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 25 Mar 2019 15:09:30 +0000 Subject: [PATCH] Fix ClientReplicationStreamProtocol.__str__ `__str__` depended on `self.addr`, which was absent from ClientReplicationStreamProtocol, so attempting to call str on such an object would raise an exception. We can calculate the peer addr from the transport, so there is no need for addr anyway. --- changelog.d/4929.misc | 1 + synapse/replication/tcp/protocol.py | 8 +++++--- synapse/replication/tcp/resource.py | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog.d/4929.misc diff --git a/changelog.d/4929.misc b/changelog.d/4929.misc new file mode 100644 index 000000000000..aaf02078b928 --- /dev/null +++ b/changelog.d/4929.misc @@ -0,0 +1 @@ +Fix `ClientReplicationStreamProtocol.__str__()`. diff --git a/synapse/replication/tcp/protocol.py b/synapse/replication/tcp/protocol.py index 55630ba9a724..148a3b8e85ee 100644 --- a/synapse/replication/tcp/protocol.py +++ b/synapse/replication/tcp/protocol.py @@ -364,8 +364,11 @@ def on_connection_closed(self): self.transport.unregisterProducer() def __str__(self): + addr = None + if self.transport: + addr = str(self.transport.getPeer()) return "ReplicationConnection" % ( - self.name, self.conn_id, self.addr, + self.name, self.conn_id, addr, ) def id(self): @@ -381,12 +384,11 @@ class ServerReplicationStreamProtocol(BaseReplicationStreamProtocol): VALID_INBOUND_COMMANDS = VALID_CLIENT_COMMANDS VALID_OUTBOUND_COMMANDS = VALID_SERVER_COMMANDS - def __init__(self, server_name, clock, streamer, addr): + def __init__(self, server_name, clock, streamer): BaseReplicationStreamProtocol.__init__(self, clock) # Old style class self.server_name = server_name self.streamer = streamer - self.addr = addr # The streams the client has subscribed to and is up to date with self.replication_streams = set() diff --git a/synapse/replication/tcp/resource.py b/synapse/replication/tcp/resource.py index 47cdf30bd3d2..7fc346c7b6f2 100644 --- a/synapse/replication/tcp/resource.py +++ b/synapse/replication/tcp/resource.py @@ -57,7 +57,6 @@ def buildProtocol(self, addr): self.server_name, self.clock, self.streamer, - addr )