From 1ab5de8ecdde942078e3961398964e55b2228b12 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Wed, 24 Jul 2013 10:13:53 +0200 Subject: [PATCH] 412418 HttpTransportOverSPDY fix race condition while sending push streams that could cause push data not to be sent. Fixes intermittent test issues in ReferrerPushStrategyTest --- .../server/http/HttpTransportOverSPDY.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java index 17a6ddd9315..41684955978 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java @@ -294,15 +294,27 @@ public class HttpTransportOverSPDY implements HttpTransport private void sendNextResourceData() { - PushResource resource; - if(active.compareAndSet(false, true)) + LOG.debug("{} sendNextResourceData active: {}", hashCode(), active.get()); + if (active.compareAndSet(false, true)) { - resource = queue.poll(); - if (resource == null) + PushResource resource = queue.poll(); + if (resource != null) + { + LOG.debug("Opening new push channel for: {}", resource); + HttpChannelOverSPDY pushChannel = newHttpChannelOverSPDY(resource.getPushStream(), resource.getPushRequestHeaders()); + pushChannel.requestStart(resource.getPushRequestHeaders(), true); return; - LOG.debug("Opening new push channel for: {}", resource); - HttpChannelOverSPDY pushChannel = newHttpChannelOverSPDY(resource.getPushStream(), resource.getPushRequestHeaders()); - pushChannel.requestStart(resource.getPushRequestHeaders(), true); + } + + if (active.compareAndSet(true, false)) + { + if (queue.peek() != null) + sendNextResourceData(); + } + else + { + throw new IllegalStateException("active must not be false here! Concurrency bug!"); + } } } @@ -336,14 +348,15 @@ public class HttpTransportOverSPDY implements HttpTransport public void failed(Throwable x) { LOG.debug("Creating push stream failed.", x); + sendNextResourceData(); } }); } private void complete() { - if(!active.compareAndSet(true, false)) - LOG.warn("complete() called and active==false? That smells like a concurrency bug!", new IllegalStateException()); + if (!active.compareAndSet(true, false)) + throw new IllegalStateException(); sendNextResourceData(); }