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

Fixes #11370 - IllegalStateException when last write fails. #11439

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented Feb 22, 2024

Removed the call to ServletChannel.abort() from the write callback.

As the write was issued from ServletChannel.handle() case COMPLETE, it was eventually calling ServletChannelState.completed(Throwable), which is expecting the requestState to be COMPLETING. However, calling abort() would set the requestState to COMPLETED, causing the IllegalStateException.

There should be no need to call abort() from the callback of failed writes, since failing the various callbacks should be enough, eventually failing the HttpStream, which would take care of tearing down the connection (HTTP/1) or the stream (HTTP/2+).

Removed the call to `ServletChannel.abort()` from the write callback.

As the write was issued from `ServletChannel.handle()` case COMPLETE, it was eventually calling `ServletChannelState.completed(Throwable)`, which is expecting the requestState to be COMPLETING.
However, calling `abort()` would set the requestState to COMPLETED, causing the IllegalStateException.

There should be no need to call `abort()` from the callback of failed writes, since failing the various callbacks should be enough, eventually failing the `HttpStream`, which would take care of tearing down the connection (HTTP/1) or the stream (HTTP/2+).

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet linked an issue Feb 22, 2024 that may be closed by this pull request
@sbordet sbordet requested a review from gregw February 23, 2024 09:58
Now aborting the response from ServletChannelState.completed(Throwable).
Fixed SizeLimitHandler exception message.

Signed-off-by: Simone Bordet <[email protected]>
@@ -143,8 +143,8 @@ public void write(boolean last, ByteBuffer content, Callback callback)
{
if (_responseLimit >= 0 && (_written + content.remaining()) > _responseLimit)
{
callback.failed(new HttpException.RuntimeException(HttpStatus.INTERNAL_SERVER_ERROR_500, "Response body is too large: " +
_written + content.remaining() + ">" + _responseLimit));
String message = "Response body is too large: %d > %d".formatted(_written + content.remaining(), _responseLimit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You put spaces around the > sign. You need to fix the test to match

Fixed SizeLimitHandlerTest.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested a review from gregw February 23, 2024 14:31
@sbordet
Copy link
Contributor Author

sbordet commented Feb 23, 2024

@gregw I reverted the renaming "aborted" -> "failed" because there are few public methods that are named abort* so felt weird to rename some (the private ones) but not others, so I kept "abort".

@sbordet sbordet merged commit 6facb0f into jetty-12.0.x Feb 26, 2024
8 checks passed
@sbordet sbordet deleted the fix/jetty-12/11370/ise-thrown-write-failed branch February 26, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

IllegalStateException when last write fails
2 participants