357240 improved ishut/oshut handling

This commit is contained in:
Greg Wilkins 2011-09-28 22:50:38 +10:00
parent 444c09fce7
commit fbf0fad076
6 changed files with 67 additions and 27 deletions

View File

@ -49,6 +49,7 @@ import org.junit.Test;
*/ */
public class HttpExchangeTest public class HttpExchangeTest
{ {
final static boolean verbose=false;
protected static int _maxConnectionsPerAddress = 2; protected static int _maxConnectionsPerAddress = 2;
protected static String _scheme = "http"; protected static String _scheme = "http";
protected static Server _server; protected static Server _server;
@ -129,7 +130,6 @@ public class HttpExchangeTest
final CountDownLatch latch = new CountDownLatch(nb); final CountDownLatch latch = new CountDownLatch(nb);
HttpExchange[] httpExchange = new HttpExchange[nb]; HttpExchange[] httpExchange = new HttpExchange[nb];
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
final boolean verbose=false;
for (int i = 0; i < nb; i++) for (int i = 0; i < nb; i++)
{ {
final int n = i; final int n = i;
@ -397,44 +397,42 @@ public class HttpExchangeTest
int size =32; int size =32;
ContentExchange httpExchange=new ContentExchange() ContentExchange httpExchange=new ContentExchange()
{ {
@Override @Override
protected synchronized void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException protected synchronized void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
{ {
System.err.println("] "+version+" "+status+" "+reason); if (verbose)
// TODO Auto-generated method stub super.onResponseStatus(version,status,reason);
super.onResponseStatus(version,status,reason);
} }
@Override @Override
protected synchronized void onResponseHeader(Buffer name, Buffer value) throws IOException protected synchronized void onResponseHeader(Buffer name, Buffer value) throws IOException
{ {
System.err.println("] "+name+": "+value); if (verbose)
// TODO Auto-generated method stub System.err.println("] "+name+": "+value);
super.onResponseHeader(name,value); super.onResponseHeader(name,value);
} }
@Override @Override
protected synchronized void onResponseContent(Buffer content) throws IOException protected synchronized void onResponseContent(Buffer content) throws IOException
{ {
System.err.println("] "+content.length()); if (verbose)
// TODO Auto-generated method stub System.err.println("] "+content.length());
super.onResponseContent(content); super.onResponseContent(content);
} }
@Override @Override
protected void onRequestComplete() throws IOException protected void onRequestComplete() throws IOException
{ {
System.err.println("] =="); if (verbose)
// TODO Auto-generated method stub System.err.println("] ==");
super.onRequestComplete(); super.onRequestComplete();
} }
@Override @Override
protected void onResponseHeaderComplete() throws IOException protected void onResponseHeaderComplete() throws IOException
{ {
System.err.println("] --"); if (verbose)
// TODO Auto-generated method stub System.err.println("] --");
super.onResponseHeaderComplete(); super.onResponseHeaderComplete();
} }

View File

@ -109,9 +109,12 @@ public class ChannelEndPoint implements EndPoint
if (_channel.isOpen() && _channel instanceof SocketChannel) if (_channel.isOpen() && _channel instanceof SocketChannel)
{ {
Socket socket= ((SocketChannel)_channel).socket(); Socket socket= ((SocketChannel)_channel).socket();
if (!socket.isClosed()&&!socket.isInputShutdown()) if (!socket.isClosed())
{ {
socket.shutdownInput(); if(socket.isOutputShutdown())
socket.close();
else if (!socket.isInputShutdown())
socket.shutdownInput();
} }
} }
} }
@ -124,9 +127,12 @@ public class ChannelEndPoint implements EndPoint
if (_channel.isOpen() && _channel instanceof SocketChannel) if (_channel.isOpen() && _channel instanceof SocketChannel)
{ {
Socket socket= ((SocketChannel)_channel).socket(); Socket socket= ((SocketChannel)_channel).socket();
if (!socket.isClosed()&&!socket.isOutputShutdown()) if (!socket.isClosed())
{ {
socket.shutdownOutput(); if (socket.isInputShutdown())
socket.close();
else if (!socket.isOutputShutdown())
socket.shutdownOutput();
} }
} }
} }
@ -170,6 +176,14 @@ public class ChannelEndPoint implements EndPoint
{ {
bbuf.position(buffer.putIndex()); bbuf.position(buffer.putIndex());
len=_channel.read(bbuf); len=_channel.read(bbuf);
LOG.debug("{} {} {} read={}",
this.getChannel().isOpen(),
this.isInputShutdown(),
this.isOutputShutdown(),
this.getChannel().isOpen(),
len);
} }
finally finally
{ {
@ -178,13 +192,17 @@ public class ChannelEndPoint implements EndPoint
} }
} }
if (len<0 && isOpen() && !isInputShutdown()) if (len<0 && isOpen())
{ {
shutdownInput(); if (!isInputShutdown())
shutdownInput();
else if (isOutputShutdown())
_channel.close();
} }
} }
catch (IOException x) catch (IOException x)
{ {
LOG.debug(x);
try try
{ {
close(); close();
@ -196,7 +214,6 @@ public class ChannelEndPoint implements EndPoint
if (len>0) if (len>0)
throw x; throw x;
LOG.ignore(x);
len=-1; len=-1;
} }
} }
@ -255,6 +272,7 @@ public class ChannelEndPoint implements EndPoint
{ {
throw new IOException("Not Implemented"); throw new IOException("Not Implemented");
} }
return len; return len;
} }

View File

@ -436,9 +436,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
public void scheduleWrite() public void scheduleWrite()
{ {
if (_writable==true) if (_writable==true)
{ LOG.debug("Required scheduleWrite {}",this);
LOG.warn("Required scheduleWrite");
}
_writable=false; _writable=false;
updateKey(); updateKey();

View File

@ -59,7 +59,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
private volatile boolean _handshook=false; private volatile boolean _handshook=false;
private boolean _allowRenegotiate=true; private boolean _allowRenegotiate=true;
private final boolean _debug = LOG.isDebugEnabled(); // snapshot debug status for optimizer private volatile boolean _debug = LOG.isDebugEnabled(); // snapshot debug status for optimizer
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public SslSelectChannelEndPoint(Buffers buffers,SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key, SSLEngine engine, int maxIdleTime) public SslSelectChannelEndPoint(Buffers buffers,SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key, SSLEngine engine, int maxIdleTime)
@ -355,6 +355,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
@Override @Override
public int fill(Buffer buffer) throws IOException public int fill(Buffer buffer) throws IOException
{ {
_debug=LOG.isDebugEnabled();
LOG.debug("{} fill",_session); LOG.debug("{} fill",_session);
// This end point only works on NIO buffer type (director // This end point only works on NIO buffer type (director
// or indirect), so extract the NIO buffer that is wrapped // or indirect), so extract the NIO buffer that is wrapped
@ -396,6 +397,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
@Override @Override
public int flush(Buffer buffer) throws IOException public int flush(Buffer buffer) throws IOException
{ {
_debug=LOG.isDebugEnabled();
LOG.debug("{} flush1",_session); LOG.debug("{} flush1",_session);
return process(null,buffer); return process(null,buffer);
} }
@ -407,6 +409,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
@Override @Override
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
{ {
_debug=LOG.isDebugEnabled();
LOG.debug("{} flush3",_session); LOG.debug("{} flush3",_session);
int len=0; int len=0;
@ -474,7 +477,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
* @return true if progress is made * @return true if progress is made
*/ */
private boolean unwrap(ByteBuffer buffer) throws IOException private boolean unwrap(ByteBuffer buffer) throws IOException
{ {
needInBuffer(); needInBuffer();
ByteBuffer in_buffer=_inNIOBuffer.getByteBuffer(); ByteBuffer in_buffer=_inNIOBuffer.getByteBuffer();
@ -482,6 +485,9 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
int total_filled=0; int total_filled=0;
boolean remoteClosed = false; boolean remoteClosed = false;
LOG.debug("{} unwrap {} {}",_session,_inNIOBuffer.space()>0,super.isOpen());
// loop filling as much encrypted data as we can into the buffer // loop filling as much encrypted data as we can into the buffer
while (_inNIOBuffer.space()>0 && super.isOpen()) while (_inNIOBuffer.space()>0 && super.isOpen())
{ {
@ -696,6 +702,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/*
@Override @Override
public void scheduleWrite() public void scheduleWrite()
{ {
@ -703,7 +710,8 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
if (!HandshakeStatus.NEED_UNWRAP.equals(_engine.getHandshakeStatus()) || super.isBufferingOutput()) if (!HandshakeStatus.NEED_UNWRAP.equals(_engine.getHandshakeStatus()) || super.isBufferingOutput())
super.scheduleWrite(); super.scheduleWrite();
} }
*/
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@Override @Override
public String toString() public String toString()

View File

@ -7,6 +7,7 @@ import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.AsyncEndPoint; import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.ChannelEndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -14,7 +15,7 @@ import org.eclipse.jetty.util.log.Logger;
public class AsyncHttpConnection extends HttpConnection public class AsyncHttpConnection extends HttpConnection
{ {
private final static int NO_PROGRESS_INFO = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_INFO",100); private final static int NO_PROGRESS_INFO = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_INFO",100);
private final static int NO_PROGRESS_CLOSE = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_CLOSE",1000); private final static int NO_PROGRESS_CLOSE = Integer.getInteger("org.mortbay.jetty.NO_PROGRESS_CLOSE",200);
private static final Logger LOG = Log.getLogger(AsyncHttpConnection.class); private static final Logger LOG = Log.getLogger(AsyncHttpConnection.class);
private int _total_no_progress; private int _total_no_progress;
@ -134,7 +135,15 @@ public class AsyncHttpConnection extends HttpConnection
_total_no_progress++; _total_no_progress++;
if (NO_PROGRESS_INFO>0 && _total_no_progress%NO_PROGRESS_INFO==0 && (NO_PROGRESS_CLOSE<=0 || _total_no_progress< NO_PROGRESS_CLOSE)) if (NO_PROGRESS_INFO>0 && _total_no_progress%NO_PROGRESS_INFO==0 && (NO_PROGRESS_CLOSE<=0 || _total_no_progress< NO_PROGRESS_CLOSE))
{
LOG.info("EndPoint making no progress: "+_total_no_progress+" "+_endp); LOG.info("EndPoint making no progress: "+_total_no_progress+" "+_endp);
LOG.setDebugEnabled(true);
Log.getLogger("org.eclipse.jetty.io.nio").getLogger("ssl").setDebugEnabled(true);
Log.getLogger(ChannelEndPoint.class).setDebugEnabled(true);
}
if (NO_PROGRESS_CLOSE>0 && _total_no_progress>NO_PROGRESS_CLOSE) if (NO_PROGRESS_CLOSE>0 && _total_no_progress>NO_PROGRESS_CLOSE)
{ {
LOG.warn("Closing EndPoint making no progress: "+_total_no_progress+" "+_endp); LOG.warn("Closing EndPoint making no progress: "+_total_no_progress+" "+_endp);

View File

@ -23,6 +23,7 @@ import javax.net.ssl.TrustManagerFactory;
import org.eclipse.jetty.http.ssl.SslContextFactory; import org.eclipse.jetty.http.ssl.SslContextFactory;
import org.eclipse.jetty.server.ConnectorTimeoutTest; import org.eclipse.jetty.server.ConnectorTimeoutTest;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test;
public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
{ {
@ -57,4 +58,12 @@ public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
} }
@Test
public void testNoProgress() throws Exception
{
testMaxIdleNoRequest();
super.testMaxIdleWithSlowRequest();
}
} }