Skip to content

Comments

libretroshare: fix reentrancy deadlock in RsEventsService::handleEvent#263

Merged
csoler merged 1 commit intoRetroShare:masterfrom
jolavillette:fix-macos-id-edit-password
Feb 18, 2026
Merged

libretroshare: fix reentrancy deadlock in RsEventsService::handleEvent#263
csoler merged 1 commit intoRetroShare:masterfrom
jolavillette:fix-macos-id-edit-password

Conversation

@jolavillette
Copy link
Contributor

@jolavillette jolavillette commented Feb 14, 2026

libretroshare: fix reentrancy deadlock in RsEventsService::handleEvent

Decoupling Event Dispatching from Service Mutexes

This change refactors the event dispatching logic in RsEventsService to prevent logical desynchronization and potential deadlocks when handlers trigger blocking operations (such as password prompts).

The Problem: Mutex Contention during Blocking Calls

Previously, event callbacks were executed while holding the service's internal mutexes (mEventQueueMtx or mHandlerMapMtx). This created a significant bottleneck:

  1. Blocking the Dispatcher: When a handler triggers a modal dialog (e.g., [askForPassword], the event dispatching thread blocks while waiting for user input.
  2. Queue Stalling: Because the mutex remains locked during this blocking window, no other threads (including the GUI) can interact with the RsEventsService. Critical system events—such as security token updates, identity status changes, or certificate validations—stay queued and unprocessed.
  3. Authentication Failures: This led to cases where valid passwords were rejected. The core system was attempting to validate credentials against an outdated internal state because the background events required to "prime" the security system were stuck behind the dispatcher's locked mutex.

The Solution: "Extract and Release" Pattern

The updated logic ensures that no mutex is held during callback execution:

  • The dispatcher now locks the mutex only long enough to extract the next handler/event.
  • The mutex is explicitly released before the callback is invoked.
  • This keeps the RsEventsService active and responsive. Other threads can continue to queue urgent events or register listeners even while one handler is waiting for a user prompt.

This decoupling ensures that the system's internal state remains consistent and up-to-date, allowing blocking operations like password validation to proceed correctly without interfering with the rest of the event-driven architecture.

@jolavillette jolavillette force-pushed the fix-macos-id-edit-password branch from 260b6a6 to 986a3d2 Compare February 17, 2026 13:42
@csoler csoler merged commit 845e8a4 into RetroShare:master Feb 18, 2026
1 check failed
@jolavillette jolavillette deleted the fix-macos-id-edit-password branch February 18, 2026 21:53
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.

2 participants