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

Arc - Decide whether req. context is active based on validity of its ContextState #38107

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

manovotn
Copy link
Contributor

@manovotn manovotn commented Jan 9, 2024

Fixes #37741

@michalvavrik Can you give this a spin please? I did test it with your first reproducer (the code-with-quarkus with added observer) but not much else yet.

I am still trying to understand why we never clear the context state from duplicated context but I didn't get any closer to an explanation yet. It could just be an optimization 🤷

I'll try to some simple test as well but I first wanted to see what CI thinks about it as I only ran tests from few modules locally.

@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Jan 9, 2024

This comment has been minimized.

Copy link
Member

@michalvavrik michalvavrik left a comment

Choose a reason for hiding this comment

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

I agree this fixes the first reproducer, but does not fix the second one (the one with gRPC security event observer, but I don't think it's related to events only).

I can see the request context state invalidated same amount of times as activated when arriving to io.quarkus.grpc.runtime.supports.context.GrpcRequestContextGrpcInterceptor#interceptCall I can see it active. You have better chance to figure why it works this way, could you look please? Separately, this change is good in my eyes, but @mkouba should decide that.

@manovotn manovotn marked this pull request as draft January 10, 2024 07:08
@manovotn
Copy link
Contributor Author

Sure, I'll take a look.
Meanwhile, I'll turn this into PR a draft.

Copy link
Contributor

@mkouba mkouba 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 that the fix is correct. The original implementation of VertxCurrentContext.remove() did not reflect the fact that RequestContextState can be invalidated before the HTTP request processing ends.

@mkouba
Copy link
Contributor

mkouba commented Jan 10, 2024

CC @franz1981 as this fix means one more volatile read per RequestContext#isActive() invocation.

@@ -112,7 +112,8 @@ public <T> T get(Contextual<T> contextual) {

@Override
public boolean isActive() {
return currentContext.get() != null;
RequestContextState requestContextState = currentContext.get();
return requestContextState == null ? false : requestContextState.isValid();
Copy link
Contributor

@franz1981 franz1981 Jan 10, 2024

Choose a reason for hiding this comment

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

It's fine, the only downside is the dependent load, but having a volatile load is pretty cheap on most architecture, and regardless... there is not much to do here, given that we requires correctness first!

@manovotn manovotn marked this pull request as ready for review January 11, 2024 15:54
@manovotn
Copy link
Contributor Author

I've added a test for this change as well and I've reached out to Michal over Zulip to discuss this further.
Contents of this PR are not a complete solution to the original issue but it is a correction of the behavior nonetheless.

Copy link

quarkus-bot bot commented Jan 11, 2024

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@mkouba mkouba merged commit b776e87 into quarkusio:main Jan 12, 2024
64 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.7 - main milestone Jan 12, 2024
@manovotn manovotn deleted the issue37741 branch January 12, 2024 10:39
mkouba added a commit to mkouba/quarkus that referenced this pull request Feb 6, 2024
mkouba added a commit to mkouba/quarkus that referenced this pull request Feb 6, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/vertx kind/bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CDI request scope deactivation does not work on duplicated context
4 participants