How-to: Enable and use actor reentrancy in Dapr

Preview feature

Actor reentrancy is currently in .

A core tenet of the virtual actor pattern is the single-threaded nature of actor execution. Before reentrancy, this caused the Dapr runtime to lock an actor on any given request. A second request could not start until the first had completed. This behavior means an actor cannot call itself, or have another actor call into it even if it is part of the same chain. Reentrancy solves this by allowing requests from the same chain or context to re-enter into an already locked actor. Examples of chains that reentrancy allows can be seen below:

Enabling actor reentrancy

Actor reentrancy is currently in preview, so enabling it is a two step process.

Before using reentrancy, the feature must be enabled in Dapr. For more information on preview configurations, see . Below is an example of the configuration for actor reentrancy:

The key to a reentrant request is the Dapr-Reentrancy-Id header. The value of this header is used to match requests to their call chain and allow them to bypass the actor’s lock.

The header is generated by the Dapr runtime for any actor request that has a reentrant config specified. Once it is generated, it is used to lock the actor and must be passed to all future requests. Below is a snippet of code from an actor handling this is Golang: