matrix-org / matrix-rust-sdk

Matrix Client-Server SDK for Rust
Apache License 2.0
1.13k stars 222 forks source link

Locks in the FFI layer are confusing #3336

Open kegsay opened 2 months ago

kegsay commented 2 months ago

There's two distinct functions to control locks:

Despite having similar names, they control different independent locks. The ClientBuilder variant controls the lock store.create_store_lock("oidc_session_refresh_lock".to_owned(), lock_value.clone()); whereas the SyncService one controls olm_machine.store().create_store_lock("cross_process_lock".to_owned(), lock_value);.

Independent to this, creating a NotificationClient implicitly creates a lock on cross_process_lock with the value LOCK_ID which is "notifications".

This is all very confusing and very very footgunny, because if 2 independent processes create NotificationClient instances they will accidentally use the same lock value!

Proposed changes:

bnjbvr commented 2 months ago

Sounds good to me :+1: Are you interested in writing a patch? :innocent: