mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 04:23:46 +00:00
tornado: Close queue connection on reload.
Tornado reloads the app whenever there is a change in code. Due to this, new connection is created to the client which also results in a new channel. To avoid creating two channels for the queue in the RabbitMQ broker we should close the old channel. Otherwise messages sent to the queue will be distributed among these two channels in a round robin scheme and we will end up losing one message since one of the channels doesn't have an active consumer. This commit closes the connection to the queue whenever Tornado reloads the application using add_reload_hook(). Fixes #5824.
This commit is contained in:
@@ -9,6 +9,7 @@ from zerver.tornado.handlers import AsyncDjangoHandler
|
||||
from zerver.tornado.socket import get_sockjs_router
|
||||
from zerver.lib.queue import get_queue_client
|
||||
|
||||
import tornado.autoreload
|
||||
import tornado.web
|
||||
|
||||
def setup_tornado_rabbitmq():
|
||||
@@ -17,6 +18,7 @@ def setup_tornado_rabbitmq():
|
||||
if settings.USING_RABBITMQ:
|
||||
queue_client = get_queue_client()
|
||||
atexit.register(lambda: queue_client.close())
|
||||
tornado.autoreload.add_reload_hook(lambda: queue_client.close()) # type: ignore # TODO: Fix missing tornado.autoreload stub
|
||||
|
||||
def create_tornado_application():
|
||||
# type: () -> tornado.web.Application
|
||||
|
||||
Reference in New Issue
Block a user