Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public ICapTransaction? Transaction
get => _asyncLocal.Value?.Transaction;
set
{
if (value == null)
{
// Clear the CapTransactionHolder held in the ExecutionContext to avoid long-term reference retention.
_asyncLocal.Value = null;
return;
}
_asyncLocal.Value ??= new CapTransactionHolder();
_asyncLocal.Value.Transaction = value;
}
Expand Down Expand Up @@ -184,6 +190,11 @@ private async Task PublishInternalAsync<T>(string name, T? value, IDictionary<st

throw;
}
finally
{
// Whether successful or exceptional, explicitly clear the transaction reference in the current context after the release is completed.
Transaction = null;
}
}

#region tracing
Expand Down