-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Make Quarkus initialization thread-safe in BaseFunction #23801
Make Quarkus initialization thread-safe in BaseFunction #23801
Conversation
A colleague found https://github.com/quarkusio/quarkus/pull/14949/files, where the lazy loading was introduced. I had tried doing a reverted version of that PR (even though I wasn't aware it existed), but that resulted in class loading issues. My change is a mix of static initialization and lazy loading. |
@rob-spoor So, there's a reason why I did initialization in the run() method, I don't remember why though. Did you actually test this on Azure Functions? |
It might have been something like boot error messages weren't viewable or something. Sorry, I wrote this years ago and should have put in a comment. |
@patriot1burke I have a test project in #23789 that showcases the issue. I've replaced the Quarkus version with a custom build, and then I no longer get any errors. That isn't run on Azure itself, but I did test the code as a local Azure function. |
...ons-http/runtime/src/main/java/io/quarkus/azure/functions/resteasy/runtime/BaseFunction.java
Outdated
Show resolved
Hide resolved
Yeah, I did this for a reason...But I can't remember Arg!!! If you look at the AWS Lambda code, its all initialized in a static block. I moved it to the run() method and lazily did it for some reason I can't remember. |
You probably ran into the same issue as I did. |
Ok, I remember now. See my comment in this thread: IIRC, the Azure Functions runtime loads the Quarkus Function class without setting TCL classloader so there would be a ton of boot failures when quarkus tried to boot. When the Function.run() method is invoked by the Azure runtime, it DOES set the TCL correctly, so that that's why Quarkus is initialized lazily in the Function.run() method and not within a static block. Keeping the old code and just changing the "started" and other fields to volatile may fix your problems. |
@patriot1burke unfortunately it wouldn't. The check for the current application isn't safe enough. The current application is set very early on in the I've listed the possible flows in #23789. We've seen both of the incorrect flows actually happen. Forcing the atomic loading by using the nested class from this PR only allows the desired success flow. |
Actually, this will have to be put in a double-check block. I'll push a separate PR. |
Are you sure that's the best solution? I've considered using that, but I remember that it can have its own issues. I've read https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java, and it lists the https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom which I've used here. |
Double check has worked since Java 5, but your solution works too. Didn't realize you had used Initializaiton-on-demand. |
Approved after CI passes. |
@patriot1burke CI is green. All good for you? |
@rob-spoor Nice PR Rob! Sorry for the confusion before. |
@patriot1burke not a problem. |
No description provided.