Skip to content

Commit 1121d24

Browse files
committed
SOLR-3696: Fix for LB/Cloud SolrClients that could leak on close() if concurrent request failed and triggered zombie server logic
1 parent 1818ae2 commit 1121d24

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ Bug Fixes
309309
and then was used to create future clients (via builder.withHttpClient), then redirect processing was wrongly
310310
disabled on the shared instance. (David Smiley)
311311

312+
* SOLR-3696: Fix for LB/Cloud SolrClients that could leak on close() if concurrent request failed and triggered zombie server logic. (hossman)
313+
312314
Dependency Upgrades
313315
---------------------
314316
(No changes)

solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public abstract class LBSolrClient extends SolrClient {
8686
private volatile EndpointWrapper[] aliveServerList = new EndpointWrapper[0];
8787

8888
private volatile ScheduledExecutorService aliveCheckExecutor;
89+
private volatile boolean isClosed = false;
8990

9091
protected long aliveCheckIntervalMillis =
9192
TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS); // 1 minute between checks
@@ -574,11 +575,16 @@ private void startAliveCheckExecutor() {
574575
// if it's not null.
575576
if (aliveCheckExecutor == null) {
576577
synchronized (this) {
578+
if (isClosed) {
579+
// must check inside sync block
580+
return;
581+
}
577582
if (aliveCheckExecutor == null) {
578583
log.debug("Starting aliveCheckExecutor for {}", this);
579584
aliveCheckExecutor =
580585
Executors.newSingleThreadScheduledExecutor(
581586
new SolrNamedThreadFactory("aliveCheckExecutor"));
587+
ObjectReleaseTracker.track(aliveCheckExecutor);
582588
aliveCheckExecutor.scheduleAtFixedRate(
583589
getAliveCheckRunner(new WeakReference<>(this)),
584590
this.aliveCheckIntervalMillis,
@@ -825,8 +831,10 @@ protected EndpointWrapper pickServer(EndpointWrapper[] aliveServerList, SolrRequ
825831
@Override
826832
public void close() {
827833
synchronized (this) {
834+
isClosed = true;
828835
if (aliveCheckExecutor != null) {
829836
ExecutorUtil.shutdownNowAndAwaitTermination(aliveCheckExecutor);
837+
ObjectReleaseTracker.release(aliveCheckExecutor);
830838
}
831839
}
832840
ObjectReleaseTracker.release(this);

0 commit comments

Comments
 (0)