Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

queue: Fix Tornado publishes failing just after losing RabbitMQ.

Alex Vandiver45f83cb16047
diff --git a/zerver/lib/queue.py b/zerver/lib/queue.py
index 89474175c42..36f467f118c 100644
--- a/zerver/lib/queue.py
+++ b/zerver/lib/queue.py
@@ -330,6 +330,8 @@ class TornadoQueueClient(QueueClient[Channel]):
) -> None:
if self.connection is None:
return
+ self.channel = None
+ self.queues = set()
self._connection_failure_count = 1
retry_secs = self.CONNECTION_RETRY_SECS
self.log.warning(
diff --git a/zerver/tests/test_queue.py b/zerver/tests/test_queue.py
index 2afad3e99be..4146f21b5af 100644
--- a/zerver/tests/test_queue.py
+++ b/zerver/tests/test_queue.py
@@ -7,6 +7,7 @@ from pika.exceptions import (
AMQPConnectionError,
ChannelClosedByBroker,
ChannelClosedByClient,
+ ChannelWrongStateError,
ConnectionClosed,
StreamLostError,
)
@@ -148,6 +149,16 @@ class TestTornadoQueueClient(ZulipTestCase):
],
)
+ # Publishes between losing the connection and reconnecting
+ # wait for the new channel, rather than using the closed one.
+ channel.basic_publish.side_effect = ChannelWrongStateError("Channel is closed.")
+ connection._on_connection_closed(mock.MagicMock(), ConnectionClosed(320, "test"))
+ connection.json_publish("test_suite", {"event": "fourth"})
+ connection._reconnect()
+ channel = open_channel(connection)
+ declare_ok(channel, "test_suite")
+ self.assertEqual(published(channel), [("test_suite", {"event": "fourth"})])
+
channel = reconnect(connection)
channel.queue_declare.assert_not_called()
channel.basic_publish.assert_not_called()
@@ -157,7 +168,7 @@ class TestTornadoQueueClient(ZulipTestCase):
"WARNING:zulip.queue:TornadoQueueClient lost connection to RabbitMQ, reconnecting in 2 secs...",
"WARNING:zulip.queue:TornadoQueueClient attempting to reconnect to RabbitMQ",
]
- * 2,
+ * 3,
)