diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java index 822c99a51f2..b61f1cbe489 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java @@ -405,7 +405,7 @@ public class HttpChannelState public void complete() { // just like resume, except don't set _dispatched=true; - boolean dispatch; + boolean handle; synchronized (this) { switch(_state) @@ -421,7 +421,7 @@ public class HttpChannelState case ASYNCWAIT: _state=State.COMPLETECALLED; - dispatch=!_expired; + handle=!_expired; break; default: @@ -429,10 +429,14 @@ public class HttpChannelState } } - if (dispatch) + if (handle) { cancelTimeout(); - scheduleDispatch(); + ContextHandler handler=getContextHandler(); + if (handler!=null) + handler.handle(_channel); + else + _channel.handle(); } } @@ -599,7 +603,11 @@ public class HttpChannelState { final AsyncContextEvent event=_event; if (event!=null) - return ((Context)event.getServletContext()).getContextHandler(); + { + Context context=((Context)event.getServletContext()); + if (context!=null) + return context.getContextHandler(); + } return null; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java index 69672f15e1b..2a595676229 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java @@ -458,7 +458,9 @@ public class StatisticsHandlerTest { final long dispatchTime = 10; final AtomicReference asyncHolder = new AtomicReference<>(); - final CyclicBarrier barrier[] = {new CyclicBarrier(2), new CyclicBarrier(2), new CyclicBarrier(2)}; + final CyclicBarrier barrier[] = {new CyclicBarrier(2), new CyclicBarrier(2)}; + final CountDownLatch latch = new CountDownLatch(1); + _statsHandler.setHandler(new AbstractHandler() { @Override @@ -540,7 +542,7 @@ public class StatisticsHandlerTest { try { - barrier[2].await(); + latch.countDown(); } catch (Exception ignored) { @@ -550,7 +552,7 @@ public class StatisticsHandlerTest long requestTime = 20; Thread.sleep(requestTime); asyncHolder.get().complete(); - barrier[2].await(); + latch.await(); assertEquals(1, _statsHandler.getRequests()); assertEquals(0, _statsHandler.getRequestsActive());