You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/03/01 09:27:14 UTC

[06/50] [abbrv] lucene-solr:jira/solr-9858: SOLR-9855: DynamicInterceptor in HttpClientUtils use synchronization that can deadlock and puts a global mutex around per request process calls.

SOLR-9855: DynamicInterceptor in HttpClientUtils use synchronization that can deadlock and puts a global mutex around per request process calls.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2f82409e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2f82409e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2f82409e

Branch: refs/heads/jira/solr-9858
Commit: 2f82409e5b3a90363941caa3767c3de2abecdaf0
Parents: be64c26
Author: markrmiller <ma...@apache.org>
Authored: Wed Feb 22 13:01:21 2017 -0500
Committer: markrmiller <ma...@apache.org>
Committed: Wed Feb 22 14:44:18 2017 -0500

----------------------------------------------------------------------
 .../org/apache/solr/client/solrj/impl/HttpClientUtil.java    | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2f82409e/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
index 7ee90e1..7a84e7f 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
@@ -19,10 +19,9 @@ package org.apache.solr.client.solrj.impl;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 import java.util.zip.GZIPInputStream;
@@ -128,7 +127,7 @@ public class HttpClientUtil {
 
   private static volatile SchemaRegistryProvider schemaRegistryProvider;
   private static volatile String cookiePolicy;
-  private static final List<HttpRequestInterceptor> interceptors = Collections.synchronizedList(new ArrayList<HttpRequestInterceptor>());
+  private static final List<HttpRequestInterceptor> interceptors = new CopyOnWriteArrayList<>();
 
 
   static {
@@ -156,6 +155,9 @@ public class HttpClientUtil {
 
     @Override
     public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
+      // don't synchronize traversal - can lead to deadlock - CopyOnWriteArrayList is critical
+      // we also do not want to have to acquire the mutex when the list is empty or put a global
+      // mutex around the process calls
       interceptors.forEach(new Consumer<HttpRequestInterceptor>() {
 
         @Override