Skip to content

Panache and Hibernate Reactive use different Vert.x local contexts #47441

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DavideD
Copy link
Contributor

@DavideD DavideD commented Apr 18, 2025

Possible fix for #47314

Draft because it needs these changes in Hibernate Reactive (next release).
@tsegismont, or @vietj, Do these changes make sense?

Thanks

@tsegismont
Copy link
Contributor

@DavideD it seems there are unrelated changes in this PR, correct?

@DavideD
Copy link
Contributor Author

DavideD commented Apr 22, 2025

Quarkus main changes quickly, but this is the important commit:
e67c91b

@DavideD
Copy link
Contributor Author

DavideD commented Apr 22, 2025

Nevermind, I rebased it and now this is the commit with the important changes: 3093299

DavideD added 2 commits April 24, 2025 11:39
In preparation to the upgrade to Vertx. 5, Hibernate Reactive
doesn't use anymore the deprecated API to access the local context.

This commits updates the way Panache access the context so that the
two extensions can comunicate.

Fix quarkusio#47314
Relats to the Hibernate Reactive issues:
* hibernate/hibernate-reactive#2176
* hibernate/hibernate-reactive#2174
* hibernate/hibernate-reactive#2207
@DavideD
Copy link
Contributor Author

DavideD commented Apr 24, 2025

@tsegismont I moved the method to access the map in ContextualDataStorage, and updated this PR. Would this work?

Do you think I also need to udpate the following code in VertxContextSafety? I don't think so but I'm not sure.

Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

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

It looks good to me, thank you @DavideD

@tsegismont
Copy link
Contributor

Do you think I also need to udpate the following code in VertxContextSafety? I don't think so but I'm not sure.

We could avoid to retrieve the Vert.x context twice, is that what you were thinking about?

Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

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

Ah, I suppose this will require a similar fix in my Panache 2 branch, due to me adding stateless sessions support in the same area.

@DavideD
Copy link
Contributor Author

DavideD commented Apr 28, 2025

We could avoid to retrieve the Vert.x context twice, is that what you were thinking about?

No, I was just wondering if you see something that might need to be updated because of the new API.

@tsegismont
Copy link
Contributor

We could avoid to retrieve the Vert.x context twice, is that what you were thinking about?

No, I was just wondering if you see something that might need to be updated because of the new API.

Well at some point (Vert.x 5 upgrade at the latest) Quarkus will have to move away from storing data in local context map.

@@ -50,8 +52,10 @@ public Key<Session> get() {
});

// This key is used to indicate that a reactive session should be opened lazily (when needed) in the current vertx context
private static final String SESSION_ON_DEMAND_KEY = "hibernate.reactive.panache.sessionOnDemand";
private static final String SESSION_ON_DEMAND_OPENED_KEY = "hibernate.reactive.panache.sessionOnDemandOpened";
private static final Key<Boolean> SESSION_ON_DEMAND_KEY = new BaseKey<>(Boolean.class,
Copy link
Member

Choose a reason for hiding this comment

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

Do not use the "key"-based API for the context local for the time being (and probably for a long time). Quarkus won't support it — we are not even sure if we will support it in Quarkus 4.

Copy link
Contributor Author

@DavideD DavideD Apr 29, 2025

Choose a reason for hiding this comment

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

In Hibernate Reactive we've been using it for a while... should I change it there too?
Should I only use String? What's the issue with using an interface as key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or by key-based you mean I shouldn't use a Map? What should I use instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Using Context local keys is not inherently wrong, in fact it's the method promoted by Vert.x (and works just fine for Hibernate Reactive when used out of Quarkus). What @cescoffier is saying is that a lot of Quarkus extensions expect to manipulate contextual in a common map, and he thinks it might be preferable to keep it this way.

That said, I'm not sure a lot of Quarkus extensions need to know the internals of contextual data storage for Hibernate Reactive, so perhaps we can stick to the changes introduced in hibernate/hibernate-reactive#2177

At this point, I'm waiting on @cescoffier to clarify the requirements for contextual data storage so that we can decide how to move forward, upstream (Vert.x, Hibernate Reactive) and in Quarkus core.

Copy link
Member

Choose a reason for hiding this comment

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

Quarkus needs to be able to list keys, copy values and manipulate the map - that's how we make sure what is propagated and what is not. Using Key objects makes this very inconvenient and would need to duplicate the whole process. So, switching to that new API means that some feature will not work with Hibernate Reactive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so the only solution right now is to stick to the deprecated API and revert the changes in Hibernate Reactive, right? Or, instead of using a Key interface, use a String.

@FroMage
Copy link
Member

FroMage commented Apr 29, 2025

Well at some point (Vert.x 5 upgrade at the latest) Quarkus will have to move away from storing data in local context map.

@tsegismont so… is context-storage going away? What is it replaced with?

@tsegismont
Copy link
Contributor

@tsegismont so… is context-storage going away? What is it replaced with?

The common contextual data map is not longer accessible from the public API in Vert.x 5. ContextInternal still has a localContextData() method that gives you this common map, but it is deprecated.

@vietj and I have started to talk about this with @cescoffier and we need to clarify the requirements.

@FroMage
Copy link
Member

FroMage commented Apr 29, 2025

OK, thanks. Lettuce know ;)

@DavideD
Copy link
Contributor Author

DavideD commented Apr 29, 2025

If I understand correctly, there's no real issue with this approach except that we will need to change it as soon as something new has been introduced. I can release Hibernate Reactive with this changes for now, right?

@tsegismont
Copy link
Contributor

If I understand correctly, there's no real issue with this approach except that we will need to change it as soon as something new has been introduced. I can release Hibernate Reactive with this changes for now, right?

If there are extensions that depend on how Hibernate Reactive stores contextual data, I would wait for @cescoffier to clarify which ones before releasing. Reading the comments from @FroMage , it sounds like Panache is one of them

@DavideD
Copy link
Contributor Author

DavideD commented Apr 29, 2025

I think Panache is the only one that needs some coordination with Hibernate Reactive. But OK, let's wait a bit

@FroMage
Copy link
Member

FroMage commented Apr 29, 2025

As long as Panache and HR use the same means of storing the session we're fine. We can change HR to match Panache, or change Panache to match HR, it doesn't matter :)

@tsegismont
Copy link
Contributor

Apparently there's also a difference in how Vert.x and Quarkus create duplicated contexts (Quarkus supports nested context). That could impact the expectations regarding contextual data. So I'd wait for @cescoffier to chime in

@markusdlugi
Copy link
Contributor

I don't want to disturb your discussion, but we're still waiting for this as fix for #47314, which is currently present in Quarkus 3.21.3 and 3.21.4 (and soon also 3.22). This bug has the potential to cause serious issues in productive applications, and it's likely that this is also affecting other HR Panache users - we were only lucky to spot it due to our good test coverage. So while I understand and appreciate the desire to find the best solution, please keep this in mind. Maybe it might be worth it to separate any major refactoring work into its own issue? Especially since the actual requirements still seem to be unclear as far as I understood your discussion.

@FroMage
Copy link
Member

FroMage commented Apr 30, 2025

Good point. Let's get a fix for this issue, and a test ASAP, and we'll see about further improvements later.

@DavideD
Copy link
Contributor Author

DavideD commented Apr 30, 2025

I'm going to revert the changes I've introduced in Hibernate Reactive and continue to use the deprecated API. We can replace them when there is a suitable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/dependencies Pull requests that update a dependency file area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/docstyle issues related for manual docstyle review area/documentation area/hibernate-validator Hibernate Validator area/maven area/mongodb area/oidc area/panache area/rest area/rest-client area/testing area/tracing area/vertx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants