Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIX] p3: race condition when *reloading* an existing db
When re-launching Odoo on an existing database in Python 3.6[0] it's
possible that the scheduler will preempt the main thread
mid-module-import and run the cron thread which causes registry (and
module) initialisation with only a subset of the Python files loaded
and thus e.g. tries loading auth_crypt with a registry in which none
of res has been loaded makes for interesting situations.

Delay spawning the cron thread until *after* the registry preload at
least, though I don't think that actually entirely fixes the issue.

[0] and probably in any Python >= 3.3, I'm guessing it's related to
    the per-module import locks which replaced the old global lock:
    https://docs.python.org/3.3/whatsnew/3.3.html#a-finer-grained-import-lock

    though since ir.cron has little reason to import anything it could
    also just be Python 3 scheduler changes which allow/cause a
    context-switch during imports while the Python 2 scheduler would
    not allow that. IDK.
  • Loading branch information
xmo-odoo committed Aug 23, 2017
1 parent cde29c2 commit e288420
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions odoo/service/server.py
Expand Up @@ -276,10 +276,6 @@ def start(self, stop=False):
# some tests need the http deamon to be available...
self.http_spawn()

if not stop:
# only relevant if we are not in "--stop-after-init" mode
self.cron_spawn()

def stop(self):
""" Shutdown the WSGI server. Wait for non deamon threads.
"""
Expand Down Expand Up @@ -323,6 +319,8 @@ def run(self, preload=None, stop=False):
self.stop()
return rc

self.cron_spawn()

# Wait for a first signal to be handled. (time.sleep will be interrupted
# by the signal handler.) The try/except is for the win32 case.
try:
Expand Down

0 comments on commit e288420

Please sign in to comment.