Let's hold off on this. I just did an analysis of the shutdown of OkHttpHttpSender, OkHttpGrpcSender, and JdkHttpSender, and they're all different. Will open a separate issue to standardize (probably mirroring the logic in OkHttpGrpcSender which is the newest).
Originally posted by @jack-berg in #8276
|
public CompletableResultCode shutdown() { |
|
client.dispatcher().cancelAll(); |
|
client.connectionPool().evictAll(); |
|
|
|
if (managedExecutor) { |
|
ExecutorService executorService = client.dispatcher().executorService(); |
|
// Use shutdownNow() to interrupt idle threads immediately since we've cancelled all work |
|
executorService.shutdownNow(); |
|
|
|
// Wait for threads to terminate in a background thread |
|
CompletableResultCode result = new CompletableResultCode(); |
|
Thread terminationThread = |
|
new Thread( |
|
() -> { |
|
try { |
|
// Wait up to 5 seconds for threads to terminate |
|
// Even if timeout occurs, we succeed since these are daemon threads |
|
boolean terminated = executorService.awaitTermination(5, TimeUnit.SECONDS); |
|
if (!terminated) { |
|
logger.log( |
|
Level.WARNING, |
|
"Executor did not terminate within 5 seconds, proceeding with shutdown since threads are daemon threads."); |
|
} |
|
} catch (InterruptedException e) { |
|
Thread.currentThread().interrupt(); |
|
} finally { |
|
result.succeed(); |
|
} |
|
}, |
|
"okhttp-shutdown"); |
|
terminationThread.setDaemon(true); |
|
terminationThread.start(); |
|
return result; |
|
} |
|
|
|
return CompletableResultCode.ofSuccess(); |
|
} |
|
@Override |
|
public CompletableResultCode shutdown() { |
|
client.dispatcher().cancelAll(); |
|
if (managedExecutor) { |
|
client.dispatcher().executorService().shutdownNow(); |
|
} |
|
client.connectionPool().evictAll(); |
|
return CompletableResultCode.ofSuccess(); |
|
} |
|
@Override |
|
public CompletableResultCode shutdown() { |
|
if (managedExecutor) { |
|
executorService.shutdown(); |
|
} |
|
if (AutoCloseable.class.isInstance(client)) { |
|
try { |
|
AutoCloseable.class.cast(client).close(); |
|
} catch (Exception e) { |
|
return CompletableResultCode.ofExceptionalFailure(e); |
|
} |
|
} |
|
return CompletableResultCode.ofSuccess(); |
|
} |
|
@Override |
|
public CompletableResultCode shutdown() { |
|
if (shutdownChannel) { |
|
channel.shutdownNow(); |
|
} |
|
return CompletableResultCode.ofSuccess(); |
|
} |
Originally posted by @jack-berg in #8276
opentelemetry-java/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSender.java
Lines 301 to 337 in 7fcacb0
opentelemetry-java/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java
Lines 204 to 212 in 7fcacb0
opentelemetry-java/exporters/sender/jdk/src/main/java/io/opentelemetry/exporter/sender/jdk/internal/JdkHttpSender.java
Lines 410 to 423 in 7fcacb0
opentelemetry-java/exporters/sender/grpc-managed-channel/src/main/java/io/opentelemetry/exporter/sender/grpc/managedchannel/internal/UpstreamGrpcSender.java
Lines 231 to 237 in 7fcacb0