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 committed Dec 3, 2024
1 parent 4d832d0 commit 507418d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
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 setBytesWritten(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 @@ -137,12 +137,15 @@ public void write(boolean last, ByteBuffer byteBuffer, Callback callback)
last = false;
try
{
if (!_wrapped && !_baseResponse.isWritingOrStreaming())
if (last && !_wrapped && !_baseResponse.isWritingOrStreaming())
{
// We can bypass the HttpOutput stream, but we need to update its bytes written
_baseResponse.getHttpOutput().setBytesWritten(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 507418d

Please sign in to comment.