Skip to content
Snippets Groups Projects
Commit 03e47dd6 authored by tsm-odoo's avatar tsm-odoo
Browse files

[FIX] bus: fix interface error on server stop


When stopping the server, all cursors are closed. The issue is that
the ImDispatch thread is kept alive until the main thread exits.

This can lead to errors during server stop: the ImDispatch thread
could try to poll an already closed connection thus raising a
`psycopg2.InterfaceError` exception.

This commit solves the issue by hiding the interface error when
it occurs during server stop.

closes odoo/odoo#100002

X-original-commit: 83777078
Signed-off-by: default avatarJulien Castiaux <juc@odoo.com>
parent c313c25f
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,11 @@ import random
import selectors
import threading
import time
from psycopg2 import InterfaceError
import odoo
from odoo import api, fields, models
from odoo.service.server import CommonServer
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.tools import date_utils
......@@ -150,7 +152,7 @@ class ImDispatch(threading.Thread):
cr.commit()
conn = cr._cnx
sel.register(conn, selectors.EVENT_READ)
while True:
while not stop_event.is_set():
if sel.select(TIMEOUT):
conn.poll()
channels = []
......@@ -165,14 +167,18 @@ class ImDispatch(threading.Thread):
websocket.trigger_notification_dispatching()
def run(self):
while True:
while not stop_event.is_set():
try:
self.loop()
except Exception:
except Exception as exc:
if isinstance(exc, InterfaceError) and stop_event.is_set():
continue
_logger.exception("Bus.loop error, sleep and retry")
time.sleep(TIMEOUT)
dispatch = None
stop_event = threading.Event()
if not odoo.multi_process or odoo.evented:
# We only use the event dispatcher in threaded and gevent mode
dispatch = ImDispatch()
CommonServer.on_stop(stop_event.set)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment