-
Notifications
You must be signed in to change notification settings - Fork 23
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
RequestScoped Context no longer works since the 2.20+(Java 17/Quarkus 3.7+) Release #319
Comments
We don't have a |
Yes, sorry I forgot a decimal. I am working on upgrading things to Java 17 and the RequestScoped issues broke my applications on anything > 2.2.x quarkus-jberet release when I tried to upgrade things. Changing the RequestScoped to ApplicationScoped fixes the issue to where the jobs run fine...but then obviously messes up quite a few things with my dependency injection on those dependencies as they are set to RequestScoped for a reason. Any help is appreciated... |
I'll have a look. |
I had a look, and it seems that is working as expected. For instance, if you start your job manually, either with the rest client, or via a resource with If the job is started via a scheduler there is no request scope available, hence the error. I don't think we should manually start a request scope context in this situation. Maybe there is something else I'm missing. Is there any chance you can provide me with a reproducer? |
Attached is a simple implementation showing the problem. I have a HelloWorld job which has a ProcessHelloWorldBatchlet and within that Batchlet there is a RequestScoped service that just generates a random GUID that the job displays. I invoke the job via the JobController and a restful endpoint to start it which leverages the job operator:
You can run the job once and it runs fine...any subsequent attempts to run the job results in a ContextNotActiveException:
|
I'va checked your code and after few tries I can say that it's just a question of timing; change batchlet code adding a sleep
and code will fail at the first try,too. |
I looked into the spec, and there are no relevant mentions of CDI scopes and how they should work or be propagated. Due to JBatch's async nature, I think it is reasonable not to expect a request-scoped bean to be propagated. Why did it work before? Well, a bug :) I think we shouldn't propagate the request context automatically, especially because there may be cases where you don't have one. Even when you have one to propagate, any request data available may be expired or out of date. My recommendation is to pass any request information as a job parameter. In other cases, like this reproducer where you have a request scoped bean with no actual request data, you could start the request scope manually by adding the |
Prior to release 2.20 the RequestScoped context functioned as expected on an injected dependency on a Batchlet. The Request Context started at the start/trigger of the job and was torn down at the end of the job completing and subsequent jobs ran with the same dependency functioned the same. However ever since release 2.20 when a job is run with a Batchlet that contains a RequestScoped context injected dependency the following error occurs:
2024-06-19 16:26:02,644 WARN [org.jberet] (executor-thread-2) JBERET000001: Failed to run batchlet org.jberet.job.model.RefArtifact@429e1416: jakarta.enterprise.context.ContextNotActiveException: RequestScoped context was not active when trying to obtain a bean instance for a client proxy of CLASS bean [class={classHere}, id={idHere}] - you can activate the request context for a specific method using the @ActivateRequestContext interceptor binding
Sometimes the job will work the first time and then subsequent calls on the job get the above error. It's a fairly simple thing to recreate by injecting a RequestScoped dependency into any batch job and then running that job and using that dependency.
The text was updated successfully, but these errors were encountered: