Bound JdkHttpSender thread pool to prevent DoS via unbounded thread creation#8276
Bound JdkHttpSender thread pool to prevent DoS via unbounded thread creation#8276abdessattar23 wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
I don't believe this is true in practice because BatchSpanProcessor, LogRecordProcessor, PeriodicMetricReader never call export concurrently. Have you seen instances where the number of threads in the pool becomes high? |
actaully yes, the batch processors export from a single worker thread, but the scenario I had in mind is That said, the change is pretty conservative, same |
|
SimpleSpanProcessor is not meant to be paired with network exporters: Its mostly a utility for testing, and for pairing with logging exporters under certain circumstances. You would definitely have lots of problems if you pairs even reasonable span / log throughput with simple processor + OTLP exporter. I don't mind be conservative the executor, but I don't love the Also, OkHttp senders are susceptible as well: |
d89bf40 to
627afe0
Compare
|
Makes sense actually, switched to the default AbortPolicy and added a try catch around CompletableFuture.supplyAsync in send() to route RejectedExecutionException to onError and kept the pool bound at max(availableProcessors, 5) and the awaitTermination in shutdown() Should the same bound be applied to the OkHttp sender as well, or keep that as a separate PR? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8276 +/- ##
============================================
- Coverage 90.29% 90.26% -0.03%
- Complexity 7672 7684 +12
============================================
Files 849 850 +1
Lines 23165 23194 +29
Branches 2341 2353 +12
============================================
+ Hits 20916 20937 +21
- Misses 1527 1531 +4
- Partials 722 726 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| executorService.awaitTermination(10, TimeUnit.SECONDS); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } |
There was a problem hiding this comment.
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).
|
Thanks!
Whatever you like. If its in this PR, there may be extra discussion to work through the okhttp behavior with thread pools. |
…reation The default executor used Integer.MAX_VALUE max threads with a SynchronousQueue, allowing thousands of threads under burst load. Cap at max(availableProcessors, 5) with CallerRunsPolicy for backpressure, and await termination on shutdown so in-flight requests complete before the HttpClient is closed.
627afe0 to
093e806
Compare
|
Sounds good, dropped the awaitTermination change, will leave that for #8280 . Keeping this PR scoped to the JdkHttpSender pool bound. Will do OkHttp in a follow-up to keep things simple. |
| onResponse.accept(httpResponse); | ||
| }); | ||
| } catch (RejectedExecutionException e) { | ||
| onError.accept(e); |
There was a problem hiding this comment.
Test coverage for this missing
There was a problem hiding this comment.
oh Thanks a lot, maybe now it's able to be merged 🙂
There was a problem hiding this comment.
Confused why this is marked resolved - I don't see any test coverage added for it. Maybe you forgot to push a commit?
There was a problem hiding this comment.
yes m sorry i didn't commit and push, now it's good
84f1b31 to
020ad50
Compare
020ad50 to
d4146be
Compare
|
now tests are good and above the 89% coverage |
The default executor used Integer.MAX_VALUE max threads with a SynchronousQueue, allowing thousands of threads under burst load. Cap at max(availableProcessors, 5) with CallerRunsPolicy for backpressure, and await termination on shutdown so in-flight requests complete before the HttpClient is closed.