From 97b48a5b93d3c159e1b62721e464a89715894684 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 17 Nov 2011 10:35:14 +1100 Subject: [PATCH] avoid double request handling when suspended --- .../jetty/server/AsyncHttpConnection.java | 11 +++++--- ...xtTest.java => LocalAsyncContextTest.java} | 24 ++++++++++++----- .../server/SelectChannelAsyncContextTest.java | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) rename jetty-server/src/test/java/org/eclipse/jetty/server/{AsyncContextTest.java => LocalAsyncContextTest.java} (94%) create mode 100644 jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java index 36edce2440f..9ed2c33c166 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java @@ -111,14 +111,19 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async reset(); - // TODO Is this required? + // TODO Is this still required? if (!_generator.isPersistent() && !_endp.isOutputShutdown()) { - LOG.warn("Safety net oshut!!!"); + LOG.warn("Safety net oshut!!! IF YOU SEE THIS, PLEASE RAISE BUGZILLA"); _endp.shutdownOutput(); } } - + else if (_request.getAsyncContinuation().isAsyncStarted()) + { + // The request is suspended, so even though progress has been made, break the while loop + LOG.debug("suspended {}",this); + break; + } } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java similarity index 94% rename from jetty-server/src/test/java/org/eclipse/jetty/server/AsyncContextTest.java rename to jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java index c0b85eb0a2c..e5b13f6dc52 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncContextTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java @@ -31,16 +31,16 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -public class AsyncContextTest +public class LocalAsyncContextTest { protected Server _server = new Server(); protected SuspendHandler _handler = new SuspendHandler(); - protected LocalConnector _connector; + protected Connector _connector; @Before public void init() throws Exception { - _connector = new LocalConnector(); + _connector = initConnector(); _server.setConnectors(new Connector[]{ _connector }); SessionHandler session = new SessionHandler(); @@ -49,6 +49,11 @@ public class AsyncContextTest _server.setHandler(session); _server.start(); } + + protected Connector initConnector() + { + return new LocalConnector(); + } @After public void destroy() throws Exception @@ -129,14 +134,21 @@ public class AsyncContextTest private synchronized String process(String content) throws Exception { - String request = "GET / HTTP/1.1\r\n" + "Host: localhost\r\n"; + String request = "GET / HTTP/1.1\r\n" + + "Host: localhost\r\n"+ + "Connection: close\r\n"; if (content==null) request+="\r\n"; else - request+="Content-Length: "+content.length()+"\r\n" + "\r\n" + content; + request+="Content-Length: "+content.length()+"\r\n" +"\r\n" + content; - return _connector.getResponses(request); + return getResponse(request); + } + + protected String getResponse(String request) throws Exception + { + return ((LocalConnector)_connector).getResponses(request); } private static class SuspendHandler extends HandlerWrapper diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java new file mode 100644 index 00000000000..35383e345cf --- /dev/null +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java @@ -0,0 +1,26 @@ +package org.eclipse.jetty.server; + +import java.net.Socket; + +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.util.IO; + +public class SelectChannelAsyncContextTest extends LocalAsyncContextTest +{ + + @Override + protected Connector initConnector() + { + return new SelectChannelConnector(); + } + + @Override + protected String getResponse(String request) throws Exception + { + SelectChannelConnector connector = (SelectChannelConnector)_connector; + Socket socket = new Socket((String)null,connector.getLocalPort()); + socket.getOutputStream().write(request.getBytes("UTF-8")); + return IO.toString(socket.getInputStream()); + } + +}