Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

Commit

Permalink
Fix potential race condition in incoming message handling (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Apr 30, 2021
1 parent 9ff891e commit d11c415
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mautrix_facebook/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ async def _handle_facebook_message(self, source: 'u.User', sender: 'p.Puppet',
# Check in-memory queues for duplicates
if oti in self._oti_dedup:
dbm = self._oti_dedup.pop(oti)
self._dedup.appendleft(msg_id)
self.log.debug(f"Got message ID {msg_id} for offline threading ID {oti} / {dbm.mxid}"
" (in dedup queue)")
self._dedup.appendleft(msg_id)
dbm.fbid = msg_id
dbm.timestamp = timestamp
await dbm.update()
Expand All @@ -804,6 +804,8 @@ async def _handle_facebook_message(self, source: 'u.User', sender: 'p.Puppet',
self.log.trace("Not handling message %s, found ID in dedup queue", msg_id)
return

self._dedup.appendleft(msg_id)

# Check database for duplicates
dbm = await DBMessage.get_by_fbid_or_oti(msg_id, oti, self.fb_receiver, sender.fbid)
if dbm:
Expand All @@ -818,7 +820,6 @@ async def _handle_facebook_message(self, source: 'u.User', sender: 'p.Puppet',
return

self.log.debug(f"Handling Facebook event {msg_id} (/{oti})")
self._dedup.appendleft(msg_id)
if not self.mxid:
mxid = await self.create_matrix_room(source)
if not mxid:
Expand Down

0 comments on commit d11c415

Please sign in to comment.