1.8 KiB
Deadlock may result when using Reentrant services
Scope
Minor
Version Introduced
4.6.2
Source Analyzer Status
Investigating
Change Description
A deadlock may result in a Reentrant service, which restricts instances of the service to one thread of execution at a time. Services prone to encounter this problem will have the following xref:System.ServiceModel.ServiceBehaviorAttribute in their code:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
- Quirked
- Build-time break
Recommended Action
To address this issue, you can do the following:
-
Set the service's concurrency mode to xref:System.ServiceModel.ConcurrencyMode.Single?displayProperty=nameWithType or <System.ServiceModel.ConcurrencyMode.Multiple?displayProperty=nameWithType>. For example:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
-
Install the latest update to the .NET Framework 4.6.2, or upgrade to a later version of the .NET Framework. This disables the flow of the xref:System.Threading.ExecutionContext in xref:System.ServiceModel.OperationContext.Current?displayProperty=nameWithType. This behavior is configurable; it is equivalent to adding the following app setting to your configuration file:
<appSettings> <add key="Switch.System.ServiceModel.DisableOperationContextAsyncFlow" value="true" /> </appSettings>
The value of
Switch.System.ServiceModel.DisableOperationContextAsyncFlow
should never be set tofalse
for Rentrant services.
Affected APIs
T:System.ServiceModel.ServiceBehaviorAttribute
F:System.ServiceModel.ConcurrencyMode.Reentrant
Category
Windows Communication Foundation (WCF)