Merge pull request #2610 from lachlan-roberts/jetty-9.4.x-issue-2592-ServerTimeoutTest-testAsyncWriteIdleTimeoutFires

Issue #2592 - fix for ServerTimeoutTest.testAsyncWriteIdleTimeoutFires [HTTP] on windows
This commit is contained in:
Greg Wilkins 2018-06-06 08:24:07 +02:00 committed by GitHub
commit 1f1a5cb064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 28 deletions

View File

@ -59,7 +59,7 @@ abstract public class WriteFlusher
// fill the state machine
__stateTransitions.put(StateType.IDLE, EnumSet.of(StateType.WRITING));
__stateTransitions.put(StateType.WRITING, EnumSet.of(StateType.IDLE, StateType.PENDING, StateType.FAILED));
__stateTransitions.put(StateType.PENDING, EnumSet.of(StateType.COMPLETING, StateType.IDLE));
__stateTransitions.put(StateType.PENDING, EnumSet.of(StateType.COMPLETING, StateType.IDLE, StateType.FAILED));
__stateTransitions.put(StateType.COMPLETING, EnumSet.of(StateType.IDLE, StateType.PENDING, StateType.FAILED));
__stateTransitions.put(StateType.FAILED, EnumSet.of(StateType.IDLE));
}
@ -512,7 +512,7 @@ abstract public class WriteFlusher
LOG.debug("failed: " + this, cause);
PendingState pending = (PendingState)current;
if (updateState(pending, __IDLE))
if (updateState(pending, new FailedState(cause)))
return pending.fail(cause);
break;
@ -532,6 +532,11 @@ abstract public class WriteFlusher
onFail(new ClosedChannelException());
}
boolean isFailed()
{
return _state.get().getType() == StateType.FAILED;
}
boolean isIdle()
{
return _state.get().getType() == StateType.IDLE;

View File

@ -252,7 +252,7 @@ public class WriteFlusherTest
Assert.assertEquals(reason, cause.getMessage());
}
Assert.assertEquals("", endPoint.takeOutputString());
Assert.assertTrue(flusher.isIdle());
Assert.assertTrue(flusher.isFailed());
}
@Test

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.server;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@ -26,7 +25,6 @@ import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritePendingException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
@ -37,6 +35,7 @@ import org.eclipse.jetty.http.HttpContent;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.IteratingCallback;
import org.eclipse.jetty.util.IteratingNestedCallback;
import org.eclipse.jetty.util.SharedBlockingCallback;
@ -283,7 +282,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
IOException ex = new IOException("Closed while Pending/Unready");
LOG.warn(ex.toString());
LOG.debug(ex);
_channel.abort(ex);
abort(ex);
return;
}
default:
@ -1043,8 +1042,16 @@ public class HttpOutput extends ServletOutputStream implements Runnable
_onError = null;
if (LOG.isDebugEnabled())
LOG.debug("onError", th);
_writeListener.onError(th);
close();
try
{
_writeListener.onError(th);
}
finally
{
IO.close(this);
}
return;
}
}
@ -1079,18 +1086,6 @@ public class HttpOutput extends ServletOutputStream implements Runnable
}
}
private void close(Closeable resource)
{
try
{
resource.close();
}
catch (Throwable x)
{
LOG.ignore(x);
}
}
@Override
public String toString()
{
@ -1332,7 +1327,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
abort(x);
_channel.getByteBufferPool().release(_buffer);
HttpOutput.this.close(_in);
IO.close(_in);
super.onCompleteFailure(x);
}
}
@ -1392,7 +1387,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
{
abort(x);
_channel.getByteBufferPool().release(_buffer);
HttpOutput.this.close(_in);
IO.close(_in);
super.onCompleteFailure(x);
}
}

View File

@ -143,6 +143,7 @@ public class ServerTimeoutsTest extends AbstractTest
{
if (t instanceof TimeoutException)
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
asyncContext.complete();
}
});
@ -494,9 +495,10 @@ public class ServerTimeoutsTest extends AbstractTest
if (failure instanceof TimeoutException)
{
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
asyncContext.complete();
handlerLatch.countDown();
}
asyncContext.complete();
}
});
}
@ -542,17 +544,17 @@ public class ServerTimeoutsTest extends AbstractTest
@Override
public void onWritePossible() throws IOException
{
output.write(new byte[64 * 1024 * 1024]);
if (output.isReady())
output.write(new byte[64 * 1024 * 1024]);
}
@Override
public void onError(Throwable failure)
{
if (failure instanceof TimeoutException)
{
asyncContext.complete();
handlerLatch.countDown();
}
asyncContext.complete();
}
});
}
@ -749,9 +751,10 @@ public class ServerTimeoutsTest extends AbstractTest
if (failure instanceof TimeoutException)
{
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
asyncContext.complete();
handlerLatch.countDown();
}
asyncContext.complete();
}
});
}