Attempt to fix issues with locks throughout the application #2351

Open
Jade wants to merge 10 commits from jade/deadlocks into main

2026-10-15

chore: Changelog
All checks were successful
Checks / Changelog / Check changelog is added (pull_request_target) Successful in 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m8s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m16s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 8m28s
2026-10-15 12:52:49 +01:00
refactor(uiaa): Defer uiaa_sessions lock until session insert
Some checks failed
Checks / Changelog / Check changelog is added (pull_request_target) Failing after 6s
Documentation / Build and Deploy Documentation (pull_request) Successful in 1m9s
Checks / Prek / Check changed files (pull_request) Successful in 6s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 1m12s
Checks / Prek / Clippy and Cargo Tests (pull_request) Has been cancelled
Do not hold the uiaa_sessions lock across device lookup in OAuth or
during initial validation. Lock the map only when inserting the newly
created session.
2026-10-15 12:44:06 +01:00
refactor(service): Use SyncRwLock and SyncMutex for in-memory services
Convert in-memory data structures in appservice, rooms::typing, and sync
wakers to use SyncRwLock and SyncMutex. Drop appservice locks before
making outbound network requests in room alias queries and federation
invites.
2026-10-15 12:43:31 +01:00
refactor(metrics): Replace std::sync::Mutex with SyncMutex
Replace std::sync::Mutex with parking_lot::Mutex (SyncMutex) in
core::metrics::runtime_intervals. Note that info::introspection retains
std::sync::Mutex because parking_lot panics in dtor after thread locals
are destroyed.
2026-10-15 12:42:31 +01:00
refactor(threepid): Use SyncMutex and decouple guard from ValidSession
Change threepid sessions and send_attempts to SyncMutex and avoid

holding the sessions mutex across callers of get_valid_session.
2026-10-15 12:41:49 +01:00
refactor(oauth): Avoid holding pending grants lock across async calls
Convert pending grants and tickets to SyncMutex and scope locks tightly

before awaiting external calls in grant_info and redeem_token.
2026-10-15 12:40:57 +01:00
refactor(service): Scope services.manager lock during lifecycle calls
Avoid holding the services.manager lock across manager.start(),

manager.stop(), and manager.poll() async invocations.
2026-10-15 12:40:01 +01:00
refactor(admin): Release handle lock before command execution
Change admin service handle to SyncRwLock and copy the handler

function pointer before awaiting execution to prevent deadlock.
2026-10-15 12:39:25 +01:00
fix(main): Prevent re-entrant read lock deadlock during reload
Reuse the already-held main_lock when checking module staleness

in run() instead of re-acquiring server.mods.read().
2026-10-15 12:38:35 +01:00
fix(service): Prevent remote join lock inversion
Do not hold state.mutex across join_remote_room to prevent an ABBA

deadlock against mutex_federation.
2026-10-15 12:37:55 +01:00