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-1758] make state field atomic in HttpServerExchange #1560

Open
wants to merge 2 commits into
base: 2.2.x
Choose a base branch
from

Conversation

burov4j
Copy link

@burov4j burov4j commented Feb 22, 2024

@fl4via fl4via added bug fix Contains bug fix(es) next release This PR will be merged before next release or has already been merged (for payload double check) waiting PR update Awaiting PR update(s) from contributor before merging labels Mar 15, 2024
@@ -165,7 +166,7 @@ public final class HttpServerExchange extends AbstractAttachable {

// mutable state

private int state = 200;
private AtomicInteger state = new AtomicInteger(200);
Copy link
Member

Choose a reason for hiding this comment

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

@burov4j Thanks for your PR!
I would like to follow the same pattern we have in XNIO. Could you instead make the field volatile and add an atomic field updater, like in this class: https://github.com/xnio/xnio/blob/3.x/api/src/main/java/org/xnio/Connection.java ?
This will have a better memory footprint than the currently proposed solution.

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -480,9 +483,9 @@ public HttpServerExchange setRequestURI(final String requestURI) {
public HttpServerExchange setRequestURI(final String requestURI, boolean containsHost) {
this.requestURI = requestURI;
if (containsHost) {
this.state |= FLAG_URI_CONTAINS_HOST;
stateUpdater.accumulateAndGet(this, FLAG_URI_CONTAINS_HOST, (state, flag) -> state | flag);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps these lambdas could be extracted to static reusable instances -- sometimes lambdas like this in hot paths aren't elided as quickly as one might wish.

Copy link
Author

Choose a reason for hiding this comment

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

Isn't this a premature optimization?

@fl4via fl4via removed the next release This PR will be merged before next release or has already been merged (for payload double check) label Apr 19, 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) waiting PR update Awaiting PR update(s) from contributor before merging
Projects
None yet
3 participants