Skip to content

Commit deeceeb

Browse files
Run JDK HTTP sender on non-daemon threads. (#7322)
Co-authored-by: Jack Berg <[email protected]>
1 parent 6bd13ff commit deeceeb

File tree

1 file changed

+22
-6
lines changed
  • exporters/sender/jdk/src/main/java/io/opentelemetry/exporter/sender/jdk/internal

1 file changed

+22
-6
lines changed

exporters/sender/jdk/src/main/java/io/opentelemetry/exporter/sender/jdk/internal/JdkHttpSender.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.opentelemetry.sdk.common.CompletableResultCode;
1414
import io.opentelemetry.sdk.common.export.ProxyOptions;
1515
import io.opentelemetry.sdk.common.export.RetryPolicy;
16+
import io.opentelemetry.sdk.internal.DaemonThreadFactory;
1617
import java.io.ByteArrayOutputStream;
1718
import java.io.IOException;
1819
import java.io.OutputStream;
@@ -32,8 +33,9 @@
3233
import java.util.concurrent.CompletableFuture;
3334
import java.util.concurrent.ConcurrentLinkedQueue;
3435
import java.util.concurrent.ExecutorService;
35-
import java.util.concurrent.Executors;
36+
import java.util.concurrent.SynchronousQueue;
3637
import java.util.concurrent.ThreadLocalRandom;
38+
import java.util.concurrent.ThreadPoolExecutor;
3739
import java.util.concurrent.TimeUnit;
3840
import java.util.function.Consumer;
3941
import java.util.function.Predicate;
@@ -101,7 +103,7 @@ public final class JdkHttpSender implements HttpSender {
101103
.map(RetryPolicy::getRetryExceptionPredicate)
102104
.orElse(JdkHttpSender::isRetryableException);
103105
if (executorService == null) {
104-
this.executorService = Executors.newFixedThreadPool(5);
106+
this.executorService = newExecutor();
105107
this.managedExecutor = true;
106108
} else {
107109
this.executorService = executorService;
@@ -133,6 +135,16 @@ public final class JdkHttpSender implements HttpSender {
133135
executorService);
134136
}
135137

138+
private static ExecutorService newExecutor() {
139+
return new ThreadPoolExecutor(
140+
0,
141+
Integer.MAX_VALUE,
142+
60,
143+
TimeUnit.SECONDS,
144+
new SynchronousQueue<>(),
145+
new DaemonThreadFactory("jdkhttp-executor"));
146+
}
147+
136148
private static HttpClient configureClient(
137149
@Nullable SSLContext sslContext,
138150
long connectionTimeoutNanos,
@@ -224,7 +236,8 @@ HttpResponse<byte[]> sendInternal(Marshaler marshaler) throws IOException {
224236
Thread.currentThread().interrupt();
225237
break; // Break out and return response or throw
226238
}
227-
// If after sleeping we've exceeded timeoutNanos, break out and return response or throw
239+
// If after sleeping we've exceeded timeoutNanos, break out and return
240+
// response or throw
228241
if ((System.nanoTime() - startTimeNanos) >= timeoutNanos) {
229242
break;
230243
}
@@ -305,12 +318,15 @@ private HttpResponse<byte[]> sendRequest(
305318
}
306319

307320
private static boolean isRetryableException(IOException throwable) {
308-
// Almost all IOExceptions we've encountered are transient retryable, so we opt out of specific
321+
// Almost all IOExceptions we've encountered are transient retryable, so we
322+
// opt out of specific
309323
// IOExceptions that are unlikely to resolve rather than opting in.
310-
// Known retryable IOException messages: "Connection reset", "/{remote ip}:{remote port} GOAWAY
324+
// Known retryable IOException messages: "Connection reset", "/{remote
325+
// ip}:{remote port} GOAWAY
311326
// received"
312327
// Known retryable HttpTimeoutException messages: "request timed out"
313-
// Known retryable HttpConnectTimeoutException messages: "HTTP connect timed out"
328+
// Known retryable HttpConnectTimeoutException messages: "HTTP connect timed
329+
// out"
314330
return !(throwable instanceof SSLException);
315331
}
316332

0 commit comments

Comments
 (0)