Hi everyone,
We’ve just released NServiceBus 7.7.4 and 6.6.3.
Fixed bugs
- #6459 Unit of work instances may get incorrectly promoted to single instance lifetime
How to know if you are affected
You are affected if:
- You are registering components with the
InstancePerUnitOfWork
lifetime. - You are using the builder inside a component factory delegate to resolve another component that was registered with the
InstancePerUnitOfWork
lifetime.
endpointConfiguration.RegisterComponents(
registration: configureComponents =>
{
configureComponents.ConfigureComponent(
componentFactory: () =>
{
return new Dependency();
},
dependencyLifecycle: DependencyLifecycle.InstancePerUnitOfWork);
});
// or
endpointConfiguration.RegisterComponents(
registration: configureComponents =>
{
configureComponents.ConfigureComponent<Dependency>(dependencyLifecycle: DependencyLifecycle.InstancePerUnitOfWork);
});
// in conjunction with
endpointConfiguration.RegisterComponents(
registration: configureComponents =>
{
configureComponents.ConfigureComponent(
componentFactory: builder =>
{
return new Instance(builder.Build<Dependency>());
},
dependencyLifecycle: DependencyLifecycle.InstancePerUnitOfWork);
});
In the above example builder.Build<Dependency>
would resolve the Dependency
on the root container and not the currently active child container which causes the lifetime of Dependency
to be escalated from DependencyLifecycle.InstancePerUnitOfWork
to DependencyLifecycle.SingleInstance
.
Symptoms
When resolving a unit of work component (e.g. Dependency
) in a component factory delegate using the provided builder, the resolved component is tracked on the root instead of the child container.
This changes the resolved component’s lifetime to SingleInstance
and causes it to be shared across multiple message executions. That in turn may lead to race conditions under concurrent message processing.
When to upgrade
You should upgrade during your next maintenance window if you are affected.
Where to get it
You can install the new versions of NServiceBus from NuGet.
With thanks,
The team in Particular
Please read our release policy for more details.