Skip to content

Comments

fix: resolve writelock contention in DoraChannel receive_p2p (#202)#285

Merged
lijingrs merged 2 commits intomofa-org:mainfrom
AdityaShome:fix/writelock-dora-channel
Feb 24, 2026
Merged

fix: resolve writelock contention in DoraChannel receive_p2p (#202)#285
lijingrs merged 2 commits intomofa-org:mainfrom
AdityaShome:fix/writelock-dora-channel

Conversation

@AdityaShome
Copy link
Contributor

@AdityaShome AdityaShome commented Feb 23, 2026

Summary

Fixes a deadlock in DoraChannel::receive_p2p where a write lock on the receivers mawas held across an async rx.recv().await, blocking all concurrent callers for up to 30 seconds.
Fixes: #202 and continues #212

Changes:

  • Changed receivers map value type from mpsc::Receiver to Arc<Mutex<mpsc::Receiver>>
  • Updated receive_p2p to acquire a brief read lock, clone the Arc, drop the map lock,
    then await on the per-agent mutex only
  • Updated try_receive_p2p with the same pattern using .lock.await()
  • Updated register_agent to wrap the new receiver in Arc::new(Mutex::new(rx))
  • Added test_p2p_receive_deadlock to reproduce and verify the fix

Testing

The added test test_p2p_receive_deadlock spawns a blocking receive and concurrently calls register_agent, asserting it completes in under 400 ms. It failed before the fix and passes after.

@AdityaShome AdityaShome force-pushed the fix/writelock-dora-channel branch from 10dceb3 to a8801c4 Compare February 23, 2026 21:48
@lijingrs lijingrs merged commit f7b21ab into mofa-org:main Feb 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Writelock in DoraChannel for extended time

2 participants