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

Improve shutdown of non-persistent HTTP/1 connections #12212 #12216

Merged
merged 9 commits into from
Sep 2, 2024

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Aug 30, 2024

Fix #12212 by improving shutdown of non-persistent HTTP/1 connections

  • shutdown in SendCallback
  • keep failsafe in Stream callback
  • improve chunk toString clarity
  • added failsafe release in onFillable, to handle case when endpoint is closed.

 + shutdown in SendCallback
 + keep failsafe in Stream callback
 + improve chunk toString clarity
 + added failsafe release in onFillable, to handle case when endpoint is closed.
@gregw
Copy link
Contributor Author

gregw commented Aug 31, 2024

@lachlan-roberts @sbordet @lorban This work builds on #12213 by moving the shutdownOutput to the SendCallback, rather than wait for the Stream callback completion (which may be long after the response is completed).

Whilst working on this, I noticed that onFillable could exit without releasing the request buffer. So I've added a failsafe release. However, it would be good to review the release logic of the class as part of the review of this PR.
I also improved the chunk toString output, as debugging was difficult with the previous verbose toString.

I believe this change may help with the HTTP/0.9 issues we have seen

@gregw gregw added High Priority Sponsored This issue affects a user with a commercial support agreement labels Aug 31, 2024
 + shutdown in SendCallback
 + keep failsafe in Stream callback
 + improve chunk toString clarity
 + added failsafe release in onFillable, to handle case when endpoint is closed.
Copy link
Contributor

@sbordet sbordet left a comment

Choose a reason for hiding this comment

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

@gregw I fail to exactly understand what this PR is fixing.

Is there a new test case to be added, or an existing one that fails?

@gregw
Copy link
Contributor Author

gregw commented Sep 1, 2024

@gregw I fail to exactly understand what this PR is fixing.

Did you read #12212 where it says:

In previous versions of jetty, we did the shutdown as the last write completed. We are now doing it as the handling callback is completed, which may be very much later than when the response is sent.
I think we should do the shutdown as soon as possible.
@sbordet thoughts?

So this is really just reverting to the behaviour that we've had for decades.

Is there a new test case to be added, or an existing one that fails?

I've written a test to check that the shutdown by a write(last) is not delayed until after callback.succeeded on the handle callback.

@gregw gregw requested a review from sbordet September 2, 2024 01:12
Copy link
Contributor

@lorban lorban left a comment

Choose a reason for hiding this comment

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

Code wise, I believe this change is good.

But the biggest issue here is IMHO that the difference between the last write and succeeding the callback is a bit tricky to implement and may need to be better javadoc'ed.

@gregw
Copy link
Contributor Author

gregw commented Sep 2, 2024

@sbordet @lorban fixing the buffer release in HttpConnection proved to be a game of whack-a-bug!
So I have removed the majority of the release "fixes" from this PR and they need to be addressed in different one. This PR now just moves the shutdown back to the sendCallback, but leaves a failsafe in the stream (apparently needed for some SSL tests).
I'd like to get this merged for this release and then look at the release issues next cycle.

The problems with release include:

  • the releaseRequestBuffer only does a conditional release of an empty buffer, when is some cases (e.g. failure, upgrade) we want to always release.
  • the releaseRequestBuffer method throws if the release is not the last one, which is counter to the concept of allowing chunks to be held with a retain.
  • when we release because the buffer has been retained, we do not release if it is not empty (e.g. if another request has been pipelined).

I think it is all mostly working, but it is fragile to changes. I think it needs a bit more time to review and perhaps a big catchall release called when the stream is completed (i.e. after both succeed/fail AND the last write has completed AND the handler thread has returned).

@gregw gregw requested a review from lorban September 2, 2024 12:29
* Removed unnecessary release of buffer in case -1 is read.
* Removed failsafe shutdown output from HttpStreamOverHTTP1.succeeded() now that is done by ContentSender.onCompleteSuccess().
* Rewritten HttpServerTestBase.testCloseWhileCompletePending using HttpTester.

Signed-off-by: Simone Bordet <[email protected]>
Signed-off-by: Simone Bordet <[email protected]>
@sbordet
Copy link
Contributor

sbordet commented Sep 2, 2024

@gregw I reduced to the minimum the changes necessary, and filed #12227 for further work.

Also, @lorban fixed a number of instabilities in #12226.

@gregw gregw merged commit 551710e into jetty-12.0.x Sep 2, 2024
10 checks passed
@gregw gregw deleted the fix/12212/earlyOutputShutdown branch September 2, 2024 21:58
sbordet added a commit that referenced this pull request Sep 9, 2024
Just improving the test code.
The flakyness was likely fixed by the work in #12216 and #12237.

Signed-off-by: Simone Bordet <[email protected]>
sbordet added a commit that referenced this pull request Sep 10, 2024
Just improving the test code.
The flakyness was likely fixed by the work in #12216 and #12237.

Signed-off-by: Simone Bordet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority Sponsored This issue affects a user with a commercial support agreement
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

ShutdownOutput for non-persistent HTTP/1 connections
3 participants