Skip to content

Commit

Permalink
Do not throw from HttpChannelState.read() method (#11369)
Browse files Browse the repository at this point in the history
Fixes #11363 by ensuring that read never throws, but instead returns an Error chunk.
  • Loading branch information
gregw authored Feb 19, 2024
1 parent 3d36825 commit b89c7eb
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -867,31 +867,37 @@ public long getLength()
@Override
public Content.Chunk read()
{
HttpStream stream;
try (AutoLock ignored = _lock.lock())
try
{
HttpChannelState httpChannel = lockedGetHttpChannelState();

Content.Chunk error = httpChannel._readFailure;
httpChannel._readFailure = Content.Chunk.next(error);
if (error != null)
return error;
HttpStream stream;
try (AutoLock ignored = _lock.lock())
{
HttpChannelState httpChannel = lockedGetHttpChannelState();

stream = httpChannel._stream;
}
Content.Chunk error = httpChannel._readFailure;
httpChannel._readFailure = Content.Chunk.next(error);
if (error != null)
return error;

Content.Chunk chunk = stream.read();
stream = httpChannel._stream;
}
Content.Chunk chunk = stream.read();

if (LOG.isDebugEnabled())
LOG.debug("read {}", chunk);
if (LOG.isDebugEnabled())
LOG.debug("read {}", chunk);

if (chunk != null && chunk.hasRemaining())
_contentBytesRead.add(chunk.getByteBuffer().remaining());
if (chunk != null && chunk.hasRemaining())
_contentBytesRead.add(chunk.getByteBuffer().remaining());

if (chunk instanceof Trailers trailers)
_trailers = trailers.getTrailers();
if (chunk instanceof Trailers trailers)
_trailers = trailers.getTrailers();

return chunk;
return chunk;
}
catch (Throwable t)
{
return Content.Chunk.from(t, true);
}
}

@Override
Expand Down

0 comments on commit b89c7eb

Please sign in to comment.