-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This handles the case where a Supply does an emit/done/quit and there is a code path that ends up looping back to the Supply itself. Due to messages on a Supply being serialized, this would result in a deadlock after the recent changes to the Supply concurrency model. Previously, it would work out for `supply`/`react` blocks due to their queueing of messages (which we eliminated due to it being a broken backpressure model and not allowing us to fix the tap-of-a-synchronous-emitter bug) and "work" (but violate the one-message-at-a-time constraint) in other cases due to the use of a reentrant mutex to manage concurrency control in non-`supply`/`react`-block cases. This fixes it with a unified approach, by adding a mechanism whereby a recursive attempt to acquire a Lock::Async will queue the work instead of blocking on the lock (which is actually non-blocking in the thread pool). Thus, we retain the backpressure for competing senders, but allow the current holder to queue messages to resolve what would be a deadlock otherwise. A holder's recursion competes fairly with outside messages, thanks to the queueing being through Lock::Async. The recursion detection uses dynamic variables, not thread IDs. This is important because stacks including a Lock::Async acquisition may move between threads over their lifetime, so we cannot simply go on thread ID. Finally, there is also a mechanism to temporarily hide a lock from the recursion detector, since the handling of doing a `whenever` that leads to synchronous emits already exists. It's interesting to consider if the mechanisms may be unified, but not immediately clear if they can be.
- Loading branch information
Showing
2 changed files
with
103 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters