Lock models when trying to decrypt events
Trying to deep-copy can result in pickling errors (#50), write-lock the models instead to avoid "dictionary changed size during iteration" issues.
This commit is contained in:
parent
c0118c4e28
commit
60fa027c2e
|
@ -1176,7 +1176,8 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
_, room_id, _ = sync_id
|
_, room_id, _ = sync_id
|
||||||
|
|
||||||
for ev in deepcopy(model).values():
|
with model.write_lock:
|
||||||
|
for ev in model.values():
|
||||||
room = self.all_rooms[room_id]
|
room = self.all_rooms[room_id]
|
||||||
|
|
||||||
if isinstance(ev.source, nio.MegolmEvent):
|
if isinstance(ev.source, nio.MegolmEvent):
|
||||||
|
@ -1189,9 +1190,11 @@ class MatrixClient(nio.AsyncClient):
|
||||||
except nio.EncryptionError:
|
except nio.EncryptionError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for cb in self.event_callbacks:
|
for callback in self.event_callbacks:
|
||||||
if not cb.filter or isinstance(decrypted, cb.filter):
|
filter_ = callback.filter
|
||||||
await asyncio.coroutine(cb.func)(room, decrypted)
|
if not filter_ or isinstance(decrypted, filter_):
|
||||||
|
coro = asyncio.coroutine(callback.func)
|
||||||
|
await coro(room, decrypted)
|
||||||
|
|
||||||
|
|
||||||
async def clear_events(self, room_id: str) -> None:
|
async def clear_events(self, room_id: str) -> None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user