Skip to content

Commit 8dba1d8

Browse files
committed
update cache inside lock
avoid concurrent cache updates
1 parent e44381d commit 8dba1d8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,18 @@ private void updateCache() {
401401
+ ", Type: "
402402
+ getConnectionTypeFromCache());
403403
}
404+
isUpdatingCache.set(false);
404405
}
405406
}
406-
isUpdatingCache.set(false);
407407
}
408408
});
409409

410410
} catch (Throwable t) {
411411
options.getLogger().log(SentryLevel.WARNING, "Failed to update connection status cache", t);
412-
cachedNetworkCapabilities = null;
413-
lastCacheUpdateTime = timeProvider.getCurrentTimeMillis();
412+
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
413+
cachedNetworkCapabilities = null;
414+
lastCacheUpdateTime = timeProvider.getCurrentTimeMillis();
415+
}
414416
}
415417
}
416418

0 commit comments

Comments
 (0)