Skip to content

Commit

Permalink
Fixed #12603 Errors logged after cross context dispatch
Browse files Browse the repository at this point in the history
Fixed #12603 Errors logged after cross context dispatch:
 + Update bytes written in HttpOutput when bypassed by optimization
 + abort if error dispatch throws
  • Loading branch information
gregw authored Dec 5, 2024
1 parent d650efe commit a3f6bda
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ public long getWritten()
return _written;
}

/**
* Used by ServletCoreResponse when it bypasses HttpOutput to update bytes written.
* @param written The bytes written
*/
void addBytesWritten(int written)
{
_written += written;
}

public void reopen()
{
try (AutoLock l = _channelState.lock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public void write(boolean last, ByteBuffer byteBuffer, Callback callback)
{
if (!_wrapped && !_servletContextResponse.isWritingOrStreaming())
{
// We can bypass the HttpOutput stream, but we need to update its bytes written
_servletContextResponse.getHttpOutput().addBytesWritten(byteBuffer.remaining());
_servletContextResponse.write(last, byteBuffer, callback);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.HostPort;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.SharedBlockingCallback.Blocker;
Expand Down Expand Up @@ -561,16 +560,7 @@ public boolean handle()
{
if (LOG.isDebugEnabled())
LOG.debug("Could not perform ERROR dispatch, aborting", x);
try
{
_response.resetContent();
sendResponseAndComplete();
}
catch (Throwable t)
{
ExceptionUtil.addSuppressedIfNotAssociated(x, t);
throw x;
}
abort(x);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ public long getWritten()
return _written;
}

/**
* Used by ServletCoreResponse when it bypasses HttpOutput to update bytes written.
* @param written The bytes written
*/
void addBytesWritten(int written)
{
_written += written;
}

public void reopen()
{
try (AutoLock l = _channelState.lock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ public void write(boolean last, ByteBuffer byteBuffer, Callback callback)
{
if (!_wrapped && !_baseResponse.isWritingOrStreaming())
{
// We can bypass the HttpOutput stream, but we need to update its bytes written
_baseResponse.getHttpOutput().addBytesWritten(byteBuffer.remaining());
_coreResponse.write(last, byteBuffer, callback);
}
else
{
// Write the byteBuffer via the HttpOutput stream or writer wrapping the stream
if (BufferUtil.hasContent(byteBuffer))
{
if (isWriting())
Expand Down Expand Up @@ -333,7 +336,10 @@ public Mutable add(HttpHeader header, String value)
@Override
public Mutable add(HttpField field)
{
_response.addHeader(field.getName(), field.getValue());
if (field.getHeader() == HttpHeader.CONTENT_LENGTH)
_response.setContentLengthLong(field.getLongValue());
else
_response.addHeader(field.getName(), field.getValue());
return this;
}

Expand Down

0 comments on commit a3f6bda

Please sign in to comment.