You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2021/06/21 21:37:46 UTC

[httpcomponents-core] branch master updated: Fix data race in StrictConnPool

This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 8eabc12  Fix data race in StrictConnPool
8eabc12 is described below

commit 8eabc124697436f7ec0b342c6a4f2f22aaafb4f9
Author: Carter Kozak <ck...@apache.org>
AuthorDate: Mon Jun 21 13:52:20 2021 -0400

    Fix data race in StrictConnPool
    
    This is an alternative to the implementation proposed in #293 as
    described by
    https://github.com/apache/httpcomponents-core/pull/293#discussion_r654678265
---
 .../src/main/java/org/apache/hc/core5/pool/StrictConnPool.java     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
index ac505d8..c9cd8b4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
@@ -657,6 +657,8 @@ public class StrictConnPool<T, C extends ModalCloseable> implements ManagedConnP
         private final Object state;
         private final Deadline deadline;
         private final BasicFuture<PoolEntry<T, C>> future;
+        // 'completed' is used internally to guard setting
+        // 'result' and 'ex', but mustn't be used by 'isDone()'.
         private final AtomicBoolean completed;
         private volatile PoolEntry<T, C> result;
         private volatile Exception ex;
@@ -695,7 +697,10 @@ public class StrictConnPool<T, C extends ModalCloseable> implements ManagedConnP
         }
 
         public boolean isDone() {
-            return this.completed.get();
+            // This method must not use 'completed.get()' which would result in a race
+            // where a caller may observe completed=true while neither result nor ex
+            // have been set yet.
+            return ex != null || result != null;
         }
 
         public void failed(final Exception ex) {