From c705bb9480e698d7e55e7b2934a05a6da2340a4a Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 22 Oct 2013 14:03:09 +0200 Subject: [PATCH] Avoid overwrite of the abort cause. --- .../org/eclipse/jetty/client/HttpRequest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java index 2a9dfb41a04..0efef0fd24b 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java @@ -36,6 +36,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jetty.client.api.ContentProvider; import org.eclipse.jetty.client.api.ContentResponse; @@ -59,6 +60,7 @@ public class HttpRequest implements Request private final Map attributes = new HashMap<>(); private final List requestListeners = new ArrayList<>(); private final List responseListeners = new ArrayList<>(); + private final AtomicReference aborted = new AtomicReference<>(); private final HttpClient client; private final long conversation; private final String host; @@ -73,7 +75,6 @@ public class HttpRequest implements Request private long timeout; private ContentProvider content; private boolean followRedirects; - private volatile Throwable aborted; public HttpRequest(HttpClient client, URI uri) { @@ -504,16 +505,19 @@ public class HttpRequest implements Request @Override public boolean abort(Throwable cause) { - aborted = Objects.requireNonNull(cause); - // The conversation may be null if it is already completed - HttpConversation conversation = client.getConversation(getConversationID(), false); - return conversation != null && conversation.abort(cause); + if (aborted.compareAndSet(null, Objects.requireNonNull(cause))) + { + // The conversation may be null if it is already completed + HttpConversation conversation = client.getConversation(getConversationID(), false); + return conversation != null && conversation.abort(cause); + } + return false; } @Override public Throwable getAbortCause() { - return aborted; + return aborted.get(); } private String buildQuery()