Issue #2592 - Failing test on Windows: ServerTimeoutsTest.testAsyncWriteIdleTimeoutFires[transport: HTTP]

removed HttpOutput.close(Closeable) method as IO.close(Closeable) should be used instead
added isFailed() method to WriteFlusher and used it to fix WriteFlusherTest.testFailWhileBlocking()
surrounded usage of onError() in HttpOutput.run() with try-finally so that IO.close(this) is executed if onError throws

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2018-06-06 15:35:54 +10:00
parent 72dcfc15e5
commit 29c9afe135
3 changed files with 19 additions and 18 deletions

View File

@ -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;
@ -36,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;
@ -1042,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;
}
}
@ -1078,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()
{
@ -1331,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);
}
}
@ -1391,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);
}
}