sonatype-lift[bot] commented on code in PR #1256:
URL: https://github.com/apache/solr/pull/1256#discussion_r1060167988


##########
solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java:
##########
@@ -2283,6 +2292,26 @@ protected CloudSolrClient getCommonCloudSolrClient() {
     return commonCloudSolrClient;
   }
 
+  protected CloudSolrClient getSolrClientForCollection(String collectionName) {
+    synchronized (this) {
+      if (!solrClientForCollectionCache.containsKey(collectionName)) {
+        CloudSolrClient solrClient =
+            getCloudSolrClient(
+                zkServer.getZkAddress(), collectionName, 
random().nextBoolean(), 5000, 120000);
+        solrClient.connect();
+        solrClientForCollectionCache.put(collectionName, solrClient);
+        if (log.isInfoEnabled()) {
+          log.info(
+              "Created solrClient for collection {} with updatesToLeaders={} 
and parallelUpdates={}",
+              collectionName,
+              solrClient.isUpdatesToLeaders(),
+              solrClient.isParallelUpdates());
+        }
+      }
+    }
+    return solrClientForCollectionCache.get(collectionName);

Review Comment:
   <picture><img alt="19% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/19/display.svg";></picture>
   
   *THREAD_SAFETY_VIOLATION:*  Read/Write race. Non-private method 
`AbstractFullDistribZkTestBase.getSolrClientForCollection(...)` reads without 
synchronization from container `this.solrClientForCollectionCache` via call to 
`Map.get(...)`. Potentially races with write in method 
`AbstractFullDistribZkTestBase.getSolrClientForCollection(...)`.
    Reporting because this access may occur on a background thread.
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=365179325&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=365179325&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=365179325&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=365179325&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=365179325&lift_comment_rating=5)
 ]



##########
solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java:
##########
@@ -1990,13 +1990,22 @@ protected void destroyServers() throws Exception {
                       IOUtils.closeQuietly(c);
                     }));
 
+    customThreadPool.submit(
+        () ->
+            solrClientForCollectionCache.values().parallelStream()
+                .forEach(
+                    c -> {
+                      IOUtils.closeQuietly(c);
+                    }));
+
     customThreadPool.submit(() -> IOUtils.closeQuietly(controlClientCloud));
 
     customThreadPool.submit(() -> IOUtils.closeQuietly(cloudClient));
 
     ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);
 
     coreClients.clear();
+    solrClientForCollectionCache.clear();

Review Comment:
   <picture><img alt="19% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/19/display.svg";></picture>
   
   *THREAD_SAFETY_VIOLATION:*  Unprotected write. Non-private method 
`AbstractFullDistribZkTestBase.destroyServers()` mutates container 
`this.solrClientForCollectionCache` via call to `Map.clear()` outside of 
synchronization.
    Reporting because another access to the same memory occurs on a background 
thread, although this access may not.
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=365180333&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=365180333&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=365180333&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=365180333&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=365180333&lift_comment_rating=5)
 ]



##########
solr/test-framework/src/java/org/apache/solr/cloud/AbstractRecoveryZkTestBase.java:
##########
@@ -81,51 +86,53 @@ public void test() throws Exception {
     }
     log.info("Indexing {} documents", maxDoc);
 
-    final StoppableIndexingThread indexThread =
-        new StoppableIndexingThread(null, cluster.getSolrClient(), "1", true, 
maxDoc, 1, true);
-    threads.add(indexThread);
-    indexThread.start();
+    try (SolrClient solrClient = 
cluster.basicSolrClientBuilder().withDefaultCollection(collection).build();) {
+      final StoppableIndexingThread indexThread =
+              new StoppableIndexingThread(null, solrClient, "1", true, maxDoc, 
1, true);
+      threads.add(indexThread);
+      indexThread.start();
 
-    final StoppableIndexingThread indexThread2 =
-        new StoppableIndexingThread(null, cluster.getSolrClient(), "2", true, 
maxDoc, 1, true);
-    threads.add(indexThread2);
-    indexThread2.start();
+      final StoppableIndexingThread indexThread2 =
+              new StoppableIndexingThread(null, solrClient, "2", true, maxDoc, 
1, true);
+      threads.add(indexThread2);
+      indexThread2.start();
 
-    // give some time to index...
-    int[] waitTimes = new int[] {200, 2000, 3000};
-    Thread.sleep(waitTimes[random().nextInt(waitTimes.length - 1)]);
+      // give some time to index...
+      int[] waitTimes = new int[]{200, 2000, 3000};
+      Thread.sleep(waitTimes[random().nextInt(waitTimes.length - 1)]);
 
-    // bring shard replica down
-    DocCollection state = getCollectionState(collection);
-    Replica leader = state.getLeader("shard1");
-    Replica replica = getRandomReplica(state.getSlice("shard1"), (r) -> 
!leader.equals(r));
+      // bring shard replica down
+      DocCollection state = getCollectionState(collection);
+      Replica leader = state.getLeader("shard1");
+      Replica replica = getRandomReplica(state.getSlice("shard1"), (r) -> 
!leader.equals(r));
 
-    JettySolrRunner jetty = cluster.getReplicaJetty(replica);
-    jetty.stop();
+      JettySolrRunner jetty = cluster.getReplicaJetty(replica);

Review Comment:
   <picture><img alt="17% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/17/display.svg";></picture>
   
   *NULL_DEREFERENCE:*  object `replica` last assigned on line 107 could be 
null and is dereferenced by call to `getReplicaJetty(...)` at line 109.
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=365180147&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=365180147&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=365180147&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=365180147&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=365180147&lift_comment_rating=5)
 ]



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to