Skip to content

SDKs send queue is no longer shutdown immediately on re-init #4564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: feat/e2e-tests-console-otel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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");
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