Skip to content

Commit 511b2c9

Browse files
authored
Merge 7cbb0cc into b5f2392
2 parents b5f2392 + 7cbb0cc commit 511b2c9

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

sentry/src/main/java/io/sentry/ShutdownHookIntegration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
3232
Objects.requireNonNull(options, "SentryOptions is required");
3333

3434
if (options.isEnableShutdownHook()) {
35-
thread = new Thread(() -> scopes.flush(options.getFlushTimeoutMillis()));
35+
thread =
36+
new Thread(() -> scopes.flush(options.getFlushTimeoutMillis()), "sentry-shutdownhook");
3637
handleShutdownInProgress(
3738
() -> {
3839
runtime.addShutdownHook(thread);

sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,23 @@ public void close(final boolean isRestarting) throws IOException {
174174
executor.shutdown();
175175
options.getLogger().log(SentryLevel.DEBUG, "Shutting down");
176176
try {
177-
// We need a small timeout to be able to save to disk any rejected envelope
178-
long timeout = isRestarting ? 0 : options.getFlushTimeoutMillis();
179-
if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
180-
options
181-
.getLogger()
182-
.log(
183-
SentryLevel.WARNING,
184-
"Failed to shutdown the async connection async sender within "
185-
+ timeout
186-
+ " ms. Trying to force it now.");
187-
executor.shutdownNow();
188-
if (currentRunnable != null) {
189-
// We store to disk any envelope that is currently being sent
190-
executor.getRejectedExecutionHandler().rejectedExecution(currentRunnable, executor);
177+
// only stop sending events on a real shutdown, not on a restart
178+
if (!isRestarting) {
179+
// We need a small timeout to be able to save to disk any rejected envelope
180+
long timeout = options.getFlushTimeoutMillis();
181+
if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
182+
options
183+
.getLogger()
184+
.log(
185+
SentryLevel.WARNING,
186+
"Failed to shutdown the async connection async sender within "
187+
+ timeout
188+
+ " ms. Trying to force it now.");
189+
executor.shutdownNow();
190+
if (currentRunnable != null) {
191+
// We store to disk any envelope that is currently being sent
192+
executor.getRejectedExecutionHandler().rejectedExecution(currentRunnable, executor);
193+
}
191194
}
192195
}
193196
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)