Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sentry/src/main/java/io/sentry/ShutdownHookIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
Objects.requireNonNull(options, "SentryOptions is required");

if (options.isEnableShutdownHook()) {
thread = new Thread(() -> scopes.flush(options.getFlushTimeoutMillis()));
thread =
new Thread(() -> scopes.flush(options.getFlushTimeoutMillis()), "sentry-shutdownhook");
Comment thread
romtsn marked this conversation as resolved.
handleShutdownInProgress(
() -> {
runtime.addShutdownHook(thread);
Expand Down
31 changes: 17 additions & 14 deletions sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,23 @@ public void close(final boolean isRestarting) throws IOException {
executor.shutdown();
options.getLogger().log(SentryLevel.DEBUG, "Shutting down");
try {
// We need a small timeout to be able to save to disk any rejected envelope
long timeout = isRestarting ? 0 : options.getFlushTimeoutMillis();
if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Failed to shutdown the async connection async sender within "
+ timeout
+ " ms. Trying to force it now.");
executor.shutdownNow();
if (currentRunnable != null) {
// We store to disk any envelope that is currently being sent
executor.getRejectedExecutionHandler().rejectedExecution(currentRunnable, executor);
// only stop sending events on a real shutdown, not on a restart
if (!isRestarting) {
// We need a small timeout to be able to save to disk any rejected envelope
long timeout = options.getFlushTimeoutMillis();
if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Failed to shutdown the async connection async sender within "
+ timeout
+ " ms. Trying to force it now.");
executor.shutdownNow();
if (currentRunnable != null) {
// We store to disk any envelope that is currently being sent
executor.getRejectedExecutionHandler().rejectedExecution(currentRunnable, executor);
}
}
}
} catch (InterruptedException e) {
Expand Down
Loading