diff --git a/CHANGELOG.md b/CHANGELOG.md index cddc5f9c67..1d1d270cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ - Only attach user attributes to logs if `sendDefaultPii` is enabled ([#5036](https://github.com/getsentry/sentry-java/pull/5036)) +### Fixes + +- Reject new logs if `LoggerBatchProcessor` is shutting down ([#5041](https://github.com/getsentry/sentry-java/pull/5041)) + ### Dependencies - Bump Native SDK from v0.12.2 to v0.12.3 ([#5012](https://github.com/getsentry/sentry-java/pull/5012)) diff --git a/sentry/src/main/java/io/sentry/logger/LoggerBatchProcessor.java b/sentry/src/main/java/io/sentry/logger/LoggerBatchProcessor.java index 290087a641..1f9b8fe7ce 100644 --- a/sentry/src/main/java/io/sentry/logger/LoggerBatchProcessor.java +++ b/sentry/src/main/java/io/sentry/logger/LoggerBatchProcessor.java @@ -38,6 +38,7 @@ public class LoggerBatchProcessor implements ILoggerBatchProcessor { private volatile @Nullable Future scheduledFlush; private final @NotNull AutoClosableReentrantLock scheduleLock = new AutoClosableReentrantLock(); private volatile boolean hasScheduled = false; + private volatile boolean isShuttingDown = false; private final @NotNull ReusableCountLatch pendingCount = new ReusableCountLatch(); @@ -51,6 +52,9 @@ public LoggerBatchProcessor( @Override public void add(final @NotNull SentryLogEvent logEvent) { + if (isShuttingDown) { + return; + } if (pendingCount.getCount() >= MAX_QUEUE_SIZE) { options .getClientReportRecorder() @@ -70,6 +74,7 @@ public void add(final @NotNull SentryLogEvent logEvent) { @SuppressWarnings("FutureReturnValueIgnored") @Override public void close(final boolean isRestarting) { + isShuttingDown = true; if (isRestarting) { maybeSchedule(true, true); executorService.submit(() -> executorService.close(options.getShutdownTimeoutMillis()));