diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java b/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java index c1acfee4e0..60ee26ea49 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java @@ -40,6 +40,7 @@ import java.util.logging.Logger; import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.CloseReason; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.FileTransfer; @@ -791,8 +792,14 @@ public void notifyCanWrite(final WriteHandler handler) { throw new IllegalStateException("Illegal attempt to set a new handler before the existing handler has been notified."); } - if (!httpContext.getCloseable().isOpen()) { - handler.onError(connection.getCloseReason().getCause()); + if (handler != null && !httpContext.getCloseable().isOpen()) { + final CloseReason closeReason = connection.getCloseReason(); + if (closeReason == null) { + LOGGER.log(Level.WARNING, "No close reason set, using default: {0}", CloseReason.LOCALLY_CLOSED_REASON); + handler.onError(CloseReason.LOCALLY_CLOSED_REASON.getCause()); + } else { + handler.onError(closeReason.getCause()); + } return; } @@ -820,6 +827,7 @@ public void notifyCanWrite(final WriteHandler handler) { // have been processed by WriteHandler.onError(). httpContext.getOutputSink().notifyCanWrite(asyncWriteHandler); } catch (Exception ignored) { + LOGGER.log(Level.FINE, "Ignoring exception.", ignored); } }