diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java index e3ebed6e248..33698d1bbc7 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java @@ -271,8 +271,8 @@ public class MetaData implements Iterable @Override public String toString() { - return String.format("%s %s %s%s%s", - getMethod(), getURI(), getVersion(), System.lineSeparator(), super.toString()); + return String.format("%s{u=%s,%s,h=%d}", + getMethod(), getURI(), getVersion(), getFields().size()); } } @@ -364,7 +364,7 @@ public class MetaData implements Iterable @Override public String toString() { - return String.format("%s %d%s%s", getVersion(), getStatus(), System.lineSeparator(), super.toString()); + return String.format("%s{s=%d,h=%d}", getVersion(), getStatus(), getFields().size()); } } } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index 1f01a9ef1b2..f428cb08a05 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -656,6 +656,13 @@ public class SslConnection extends AbstractConnection } } } + catch (IllegalStateException e) + { + // Some internal error in SSLEngine + LOG.debug(e); + getEndPoint().close(); + throw new EofException(e); + } catch (Exception e) { getEndPoint().close(); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index 6bd4e30d43d..09126461de5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -514,12 +514,12 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co private class Acceptor implements Runnable { - private final int _acceptor; + private final int _id; private String _name; private Acceptor(int id) { - _acceptor = id; + _id = id; } @Override @@ -527,7 +527,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { final Thread thread = Thread.currentThread(); String name=thread.getName(); - _name=String.format("%s-acceptor-%d@%x-%s",name,_acceptor,hashCode(),AbstractConnector.this.toString()); + _name=String.format("%s-acceptor-%d@%x-%s",name,_id,hashCode(),AbstractConnector.this.toString()); thread.setName(_name); int priority=thread.getPriority(); @@ -536,7 +536,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co synchronized (AbstractConnector.this) { - _acceptors[_acceptor] = thread; + _acceptors[_id] = thread; } try @@ -545,7 +545,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { try { - accept(_acceptor); + accept(_id); } catch (Throwable e) { @@ -564,7 +564,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co synchronized (AbstractConnector.this) { - _acceptors[_acceptor] = null; + _acceptors[_id] = null; } CountDownLatch stopping=_stopping; if (stopping!=null) @@ -577,7 +577,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co { String name=_name; if (name==null) - return String.format("acceptor-%d@%x", _acceptor, hashCode()); + return String.format("acceptor-%d@%x", _id, hashCode()); return name; } 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 2364588c62e..509bc616c19 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 @@ -563,6 +563,14 @@ public class HttpChannelState event.cancelTimeoutTask(); } + public boolean isIdle() + { + synchronized (this) + { + return _state==State.IDLE; + } + } + public boolean isExpired() { synchronized (this) @@ -613,6 +621,7 @@ public class HttpChannelState } } + public boolean isAsync() { synchronized (this) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index efd4fd88e5a..2f194da99c7 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -32,6 +32,7 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EofException; +import org.eclipse.jetty.server.HttpChannelState.State; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IteratingCallback; @@ -197,6 +198,12 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http LOG.debug("{} onFillable enter {}", this, _channel.getState()); final HttpConnection last=setCurrentConnection(this); + + // If the channel state is not idle, then a request is in progress and + // has previously been dispatched. Thus if this call to onFillable produces + // a parsed event, it will be handled by the channel mechanism and this call + // does not need to call fillInterested + final boolean handling = !_channel.getState().isIdle(); try { @@ -220,8 +227,8 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http { boolean suspended = !_channel.handle(); - // We should break iteration if we have suspended or changed connection - if (suspended || getEndPoint().getConnection() != this ) + // We should break iteration if we have suspended or changed connection or this is not the handling thread. + if (suspended || getEndPoint().getConnection() != this || handling ) break; } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index 7bb7fdc8266..e3dfb171760 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -356,6 +356,10 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture InputStream is=client.getInputStream(); Assert.assertFalse(client.isClosed()); + OutputStream os=client.getOutputStream(); + os.write("GET ".getBytes("utf-8")); + os.flush(); + Thread.sleep(sleepTime); long start = System.currentTimeMillis(); try @@ -365,7 +369,35 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture } catch(SSLException e) { + e.printStackTrace(); + } + catch(Exception e) + { + e.printStackTrace(); + } + Assert.assertTrue(System.currentTimeMillis() - start < maximumTestRuntime); + } + + @Test(timeout=60000) + public void testMaxIdleNothingSent() throws Exception + { + configureServer(new EchoHandler()); + Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort()); + client.setSoTimeout(10000); + InputStream is=client.getInputStream(); + Assert.assertFalse(client.isClosed()); + + Thread.sleep(sleepTime); + long start = System.currentTimeMillis(); + try + { + IO.toString(is); + Assert.assertEquals(-1, is.read()); + } + catch(SSLException e) + { + // e.printStackTrace(); } catch(Exception e) { diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties index d2d9f09e73e..adf68c7c337 100644 --- a/jetty-server/src/test/resources/jetty-logging.properties +++ b/jetty-server/src/test/resources/jetty-logging.properties @@ -1,3 +1,3 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -org.eclipse.jetty.LEVEL=DEBUG +#org.eclipse.jetty.LEVEL=DEBUG #org.eclipse.jetty.server.LEVEL=DEBUG diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index 2c4763b1313..afde5ba9a49 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -93,6 +93,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject; public class StdErrLog extends AbstractLogger { private static final String EOL = System.getProperty("line.separator"); + private static int __tagpad = Integer.getInteger("org.eclipse.jetty.util.log.StdErrLog.TAG_PAD",50); private static DateCache _dateCache; private static final Properties __props = new Properties(); @@ -100,7 +101,9 @@ public class StdErrLog extends AbstractLogger Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.SOURCE","false"))); private final static boolean __long = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.LONG","false")); private final static boolean __escape = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.ESCAPE","true")); - + + + static { __props.putAll(Log.__props); @@ -127,6 +130,11 @@ public class StdErrLog extends AbstractLogger } } + public static void setTagPad(int pad) + { + __tagpad=pad; + } + public static final int LEVEL_ALL = 0; public static final int LEVEL_DEBUG = 1; public static final int LEVEL_INFO = 2; @@ -590,29 +598,23 @@ public class StdErrLog extends AbstractLogger } buffer.append(ms).append(tag); - int p=buffer.length(); - if (_printLongNames) + String name=_printLongNames?_name:_abbrevname; + String tname=Thread.currentThread().getName(); + + int p=__tagpad>0?(name.length()+tname.length()-__tagpad):0; + + if (p<0) { - buffer.append(_name); + buffer + .append(name) + .append(':') + .append(" ",0,-p) + .append(tname); } - else + else if (p==0) { - buffer.append(_abbrevname); + buffer.append(name).append(':').append(tname); } - p=buffer.length()-p-25; - if (p>0) - buffer.setLength(buffer.length()-p); - else - buffer.append(" ",0,-p); - buffer.append(':'); - - p=buffer.length(); - buffer.append(Thread.currentThread().getName()); - p=buffer.length()-p-20; - if (p>0) - buffer.setLength(buffer.length()-p); - else - buffer.append(" ",0,-p); buffer.append(':'); if (_source) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java index daa5901c3ff..28b63ad32d8 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java @@ -38,6 +38,11 @@ import org.junit.Test; */ public class StdErrLogTest { + static + { + StdErrLog.setTagPad(0); + } + @Before public void before() {