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 #5888 - Limit usage of HTTP/2 connections. #12401

Merged

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented Oct 17, 2024

  • Made the high-level HttpConnectionOverHTTP2 implement MaxUsable, so it cannot be used to open more streams than allowed.
  • Implemented low-level handling of explicit stream ids provided by applications.
  • Implemented low-level handling of stream id overflow.
  • Added test cases.

* Made the high-level HttpConnectionOverHTTP2 implement MaxUsable, so it cannot be used to open more streams than allowed.
* Implemented low-level handling of explicit stream ids provided by applications.
* Implemented low-level handling of stream id overflow.
* Added test cases.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested a review from lorban October 17, 2024 15:54
@sbordet sbordet linked an issue Oct 17, 2024 that may be closed by this pull request
@lorban
Copy link
Contributor

lorban commented Oct 23, 2024

Overall, LGTM but these changes introduce a bug caught by PriorityTest.

* Now using a placeholder HTTP2Stream for streams opened with a PRIORITY, but not yet with a HEADERS.

Signed-off-by: Simone Bordet <[email protected]>
* Fixed maxUsage check in AbstractConnectionPool.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested a review from gregw October 28, 2024 20:44
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Sorry but the algorithm this code is trying to implement is too opaque without comments. I can't say that it is wrong, but it looks very arbitrary, so a bit of explanation would be good.

@sbordet
Copy link
Contributor Author

sbordet commented Oct 29, 2024

Note to self:

  • Using a placeholder stream is nice for idle timeouts, but messes with the local stream count.
  • Using a side map seems simpler, but requires timeout handling

Now their streams ids are stored in a side Set.

Signed-off-by: Simone Bordet <[email protected]>
Introduced HTTP2Session.maxTotalLocalStreams to limit the max number of streams that might be created in a connection.

Linked this new property with the high-level AbstractConnectionPool.maxUsage.

Signed-off-by: Simone Bordet <[email protected]>
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.

I think the new reserveSlot() logic deserves a try at simplifying it as its complexity exploded which made it rather hard to read.

Otherwise the new stream limitation LGTM.

streamId = localStreamIds.getAndAdd(2);
reserved = true;
// Stream id is given.
while (true)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a long maze of ifs and elses in a while loop that partially duplicates the logic of the enclosing if branch, and is quite involved to follow.

Can't this be simplified and de-duplicated?

Signed-off-by: Simone Bordet <[email protected]>
@lorban lorban self-requested a review October 30, 2024 18:43
@sbordet sbordet merged commit b9cdfd3 into jetty-12.0.x Oct 31, 2024
10 checks passed
@sbordet sbordet deleted the fix/jetty-12.0.x/5888/limit-usage-h2-connections branch October 31, 2024 15:54
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.

Limit usage of HTTP/2 connections
3 participants