HomePhabricator
Diffusion Comm 4e3a7d067512

[native] Implement utils to lock MMKV for entire sequence of operations and use…

Description

[native] Implement utils to lock MMKV for entire sequence of operations and use to to sync encryption and decryption of notifs

Summary:
This differential implements utils to avoid data races between the main app and the notifs code. By default MMKV synchronizes only for a single operation (read , write or removal). Unfortunately this opens the gate for data races against notif encryption and decryption that happen on different thread/proces and involve reading and writing back the state of the olm session.

MMKV exposes public methods to lock and unlock the database for the sequence of operations. I wasn't aware of them since they are not mentioned in the documentation so I had to dig them up in the code.
They look like these: https://github.com/Tencent/MMKV/blob/v1.3.5/Core/MMKV.cpp#L1190-L1201, https://github.com/Tencent/MMKV/blob/v1.3.5/Core/MMKV.h#L396-L399

Test Plan: Added logs to introduced methods informing when the lock is acquired and when released. Sent e2ee notifs back and forth and examined the logs.

Reviewers: kamil, tomek, bartek

Reviewed By: bartek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D12958