379046 avoid closing idle connections from selector thread
This commit is contained in:
parent
98ed2a9d9a
commit
d80be96e41
|
@ -283,12 +283,18 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
|||
|
||||
if (idleTimestamp!=0 && _maxIdleTime>0)
|
||||
{
|
||||
long idleForMs=now-idleTimestamp;
|
||||
final long idleForMs=now-idleTimestamp;
|
||||
|
||||
if (idleForMs>_maxIdleTime)
|
||||
{
|
||||
onIdleExpired(idleForMs);
|
||||
_idleTimestamp=now;
|
||||
_manager.dispatch(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
onIdleExpired(idleForMs);
|
||||
_idleTimestamp=System.currentTimeMillis();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.greaterThan;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
|
@ -24,6 +25,7 @@ import org.eclipse.jetty.io.AsyncEndPoint;
|
|||
import org.eclipse.jetty.io.ConnectedEndPoint;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -360,17 +362,17 @@ public class SelectChannelEndPointTest
|
|||
int b=client.getInputStream().read();
|
||||
assertEquals(-1,b);
|
||||
long idle=System.currentTimeMillis()-start;
|
||||
assertTrue(idle>400);
|
||||
assertTrue(idle<2000);
|
||||
assertThat(idle,Matchers.greaterThan(400L));
|
||||
assertThat(idle,Matchers.lessThan(3000L));
|
||||
|
||||
// But endpoint is still open.
|
||||
assertTrue(_lastEndp.isOpen());
|
||||
if (_lastEndp.isOpen())
|
||||
{
|
||||
// half close so wait another idle period
|
||||
assertTrue(_lastEndp.isOutputShutdown());
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
||||
|
||||
// Wait for another idle callback
|
||||
Thread.sleep(2000);
|
||||
// endpoint is closed.
|
||||
|
||||
assertFalse(_lastEndp.isOpen());
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue