diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java index 6c580bfe7bc..b3e8c358386 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java @@ -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; diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java index f472544c13c..61280f224e6 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java @@ -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 diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java index 8af7217ae18..6fcd6370435 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpOutput.java @@ -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); } }