Skip to content

Commit eedc4fa

Browse files
authored
fix: Fixed race condition in ANR Integration (#2045)
1 parent 4863bd2 commit eedc4fa

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Fixed a potential race condition in the ANR watchdog integration ([2045](https://github.com/getsentry/sentry-unity/pull/2045))
8+
59
### Dependencies
610

711
- Bump .NET SDK from v5.1.1 to v5.2.0 ([#2040](https://github.com/getsentry/sentry-unity/pull/2040))

src/Sentry.Unity/Integrations/AnrIntegration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private IEnumerator UpdateUiStatus()
126126
yield return waitForSeconds;
127127
while (!_stop)
128128
{
129-
_ticksSinceUiUpdate = 0;
129+
Interlocked.Exchange(ref _ticksSinceUiUpdate, 0);
130130
_reported = false;
131131
yield return waitForSeconds;
132132
}
@@ -144,12 +144,12 @@ private void Run()
144144

145145
while (!_stop)
146146
{
147-
_ticksSinceUiUpdate++;
147+
Interlocked.Increment(ref _ticksSinceUiUpdate);
148148
Thread.Sleep(SleepIntervalMs);
149149

150150
if (Paused)
151151
{
152-
_ticksSinceUiUpdate = 0;
152+
Interlocked.Exchange(ref _ticksSinceUiUpdate, 0);
153153
}
154154
else if (_ticksSinceUiUpdate >= reportThreshold && !_reported)
155155
{

0 commit comments

Comments
 (0)