From b2be277ff37cffef10055eb141108b8a9847499e Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Mon, 7 Jun 2021 13:36:55 +0200 Subject: Ensure dispatch thread is shut down --- .../src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'vespa-feed-client') diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java index 7a6e2120be6..a805c7eb195 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/HttpRequestStrategy.java @@ -63,12 +63,15 @@ class HttpRequestStrategy implements RequestStrategy { this.maxInflight = builder.connectionsPerEndpoint * (long) builder.maxStreamsPerConnection; this.minInflight = builder.connectionsPerEndpoint * (long) min(16, builder.maxStreamsPerConnection); this.targetInflightX10 = new AtomicLong(10 * (long) (Math.sqrt(minInflight) * Math.sqrt(maxInflight))); - new Thread(this::dispatch, "feed-client-dispatcher").start(); + + Thread dispatcher = new Thread(this::dispatch, "feed-client-dispatcher"); + dispatcher.setDaemon(true); + dispatcher.start(); } private void dispatch() { try { - while (breaker.state() != OPEN) { + while (breaker.state() != OPEN && ! destroyed.get()) { while ( ! isInExcess() && poll() && breaker.state() == CLOSED); // Sleep when circuit is half-open, nap when queue is empty, or we are throttled. Thread.sleep(breaker.state() == HALF_OPEN ? 1000 : 10); -- cgit v1.2.3