[FIX] google_(account|calendar): Concurrent Synchro

Each time the calendar view of event.calendar is loaded,
the synchronization with google calendar was launched
and if a user open many tabs, it can lead to deadlock

Solution: Check for lock before launching the synchro,
if the transaction cannot acquire the lock, it's proably
because another synchro already started

closes odoo/odoo#69540

X-original-commit: 101598fae6fc32a49bb6d422a82b621a81201cb5
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Thibault Francois
2021-04-20 12:23:10 +00:00
parent 2a07d7b8f9
commit e564b0d8da
2 changed files with 11 additions and 3 deletions
@@ -146,14 +146,14 @@ class GoogleService(models.AbstractModel):
res.raise_for_status()
status = res.status_code
if int(status) in (204, 404): # Page not found, no response
if int(status) == 204: # Page not found, no response
response = False
else:
response = res.json()
try:
ask_time = datetime.strptime(res.headers.get('date'), "%a, %d %b %Y %H:%M:%S %Z")
except:
ask_time = datetime.strptime(res.headers.get('date', ''), "%a, %d %b %Y %H:%M:%S %Z")
except ValueError:
pass
except requests.HTTPError as error:
if error.response.status_code in (204, 404):
@@ -97,6 +97,14 @@ class User(models.Model):
self.ensure_one()
if self.google_synchronization_stopped:
return False
# don't attempt to sync when another sync is already in progress, as we wouldn't be
# able to commit the transaction anyway (row is locked)
self.env.cr.execute("""SELECT id FROM res_users WHERE id = %s FOR NO KEY UPDATE SKIP LOCKED""", [self.id])
if not self.env.cr.rowcount:
_logger.info("skipping calendar sync, locked user %s", self.login)
return False
full_sync = not bool(self.google_calendar_sync_token)
with google_calendar_token(self) as token:
try: