Skip to content

Commit cb7b258

Browse files
Workaround stale Scope.Transaction issue
1 parent 77cd0cd commit cb7b258

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Sentry.Maui.CommunityToolkit.Mvvm/MauiCommunityToolkitMvvmEventsBinder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ private void RelayCommandOnPropertyChanged(object? sender, PropertyChangedEventA
147147
// results would be that we would store the transaction on the scope, but it would never be cleared again,
148148
// since the next call to OnPropertyChanged for this RelayCommand will (likely) be from a different thread.
149149
var span = hub.StartSpan(SpanName, SpanOp);
150+
if (span is ITransactionTracer transaction)
151+
{
152+
hub.ConfigureScope(scope => scope.Transaction = transaction);
153+
}
154+
150155
relay.SetFused(span);
151156
}
152157
else if (relay.GetFused<ISpan>() is { } span)

src/Sentry/Scope.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ public ITransactionTracer? Transaction
212212
_transactionLock.EnterReadLock();
213213
try
214214
{
215-
return _transaction.Value;
215+
// Workaround for https://github.com/getsentry/sentry-dotnet/pull/4125#discussion_r2087994417
216+
// TODO: We should really find the root cause of this issue and address in a seprate PR
217+
return _transaction.Value is { IsFinished: false } transaction ? transaction : null;
216218
}
217219
finally
218220
{

0 commit comments

Comments
 (0)