Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNDERTOW-2448] At ServletPrintWriter.write(CharBuffer) do not mark e… #1683

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

fl4via
Copy link
Member

@fl4via fl4via commented Oct 15, 2024

…rror if buffer.remaining() == remaining after flush. We need to update remaining to do a proper check here.

The aforementioned == check can return true after a successfull flush, because "remaining" value is set to be the size of the bytes remaining in the buffer before encoding. If, at that stage, the buffer is empty, "remaining" value is set to buffer.capacity(). When encoding many bytes, we will end up with a full buffer. As a result, we will try to flush, and it is often the case that the buffer will be entirely cleared after flushing. This results in buffer.remaining() being the overall buffer size, i.e., buffer.capacity(). As a result, buffer.remaining() == remaining check returns true, and write is aborted, causing the broken responses we are seeing.

Jira: https://issues.redhat.com/browse/UNDERTOW-2448

@fl4via fl4via added bug fix Contains bug fix(es) waiting CI check Ready to be merged but waiting for CI check labels Oct 15, 2024
@fl4via fl4via added the next release This PR will be merged before next release or has already been merged (for payload double check) label Oct 15, 2024
…rror if buffer.remaining() == remaining after flush. We need to update remaining to do a proper check here.

The aforementioned == check can return true after a successfull flush, because "remaining" value is set to be the size of the bytes remaining in the buffer before encoding. If, at that stage, the buffer is empty, "remaining" value is set to buffer.capacity(). When encoding many bytes, we will end up with a full buffer. As a result, we will try to flush, and it is often the case that the buffer will be entirely cleared after flushing. This results in buffer.remaining() being the overall buffer size, i.e., buffer.capacity(). As a result, buffer.remaining() == remaining check returns true, and write is aborted, causing the broken responses we are seeing.

Signed-off-by: Flavia Rainone <[email protected]>
@fl4via fl4via removed the waiting CI check Ready to be merged but waiting for CI check label Oct 16, 2024
@fl4via fl4via merged commit 86170f7 into undertow-io:main Oct 16, 2024
13 of 16 checks passed
@fl4via fl4via removed the next release This PR will be merged before next release or has already been merged (for payload double check) label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Contains bug fix(es)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants