-
Notifications
You must be signed in to change notification settings - Fork 38
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
Reactive CompletionStage backed by ManagedExecutorService #40
Comments
@mkarg Commented |
|
I should point out that a solution to this is being prototyped under the MicroProfile Concurrency spec (MicroProfile FaultTolerance spec requires this function), with the hope that it will be brought back into Jakarta EE Concurrency once new releases of EE specs are ready to start incorporating enhancements. |
I think we should start gathering some requirements for a next version of concurrency utils and start a new release plan. |
@smillidge agreed. A couple of good sources of requirements will be the various issues opened against this repo, as well as what has gone into MicroProfile Concurrency. I assume the cu-dev mailing list will be the best place for the discussion. |
Once we are allowed to start on Jakarta EE 10 work (some time after the package rename occurs for Jakarta EE 9), I'll volunteer to put together a pull for this issue that copies over the following interface methods from the MicroProfile managed executor, all of which parallel java.util.concurrent.CompletableFuture's static methods and newIncompleteFuture method for creating completable futures/completion stages,
This, in addition to copying over some JavaDoc at the class level that defines what it means for a completion stage to be backed by a managed executor, should get Jakarta EE up to the point of matching, in a fully compatible way, what Microprofile provides around managed executor backed completion stages. All of the other MicroProfile Context Propagation enhancements/features can be covered in separate issues, which will allow the Jakarta EE Concurrency participants to decide on a granular basis what to accept into Jakarta EE and what not to. |
We are allowed to do Jakarta EE 10 work now. Maybe in the first instance merge the namespace change to the 2.0 branch and then branch off that. |
Signed-off-by: Nathan Rauh <nathan.rauh@us.ibm.com>
Signed-off-by: Nathan Rauh <nathan.rauh@us.ibm.com>
Signed-off-by: Nathan Rauh <nathan.rauh@us.ibm.com>
There is a discussion in the JAX-RS expert group list (jaxrs-spec@javaee.groups.io : Clarification regarding ManagedExecutorService in Rx Client) regarding the use of managed executors for the JAX-RS reactive client. Specifically, it has been pointed out that while the JAX-RS 2.1 spec requires the ability to create a CompletionStage with a ManagedExecutorService as its default asynchronous execution facility, there is currently no means for a JAX-RS provider to implement this requirement such that it behaves in a reliable way with respect to thread context propagation.
This situation arises because CompletionStage async methods that add dependent stages are sometimes a deferred submit of the task and sometimes not, depending on whether or not the parent stage happens to have already completed. If the parent stage is already completed, the submit is not deferred, and thread context can naturally be captured from the thread that adds the dependent stage, as would be expected. However, if the parent stage has not completed, the submit is deferred until such point in time as the parent stage completes, after which the task to run the dependent stage is submitted, however, inheriting the wrong thread context - the context under which the parent stage ran.
The non-deterministic behavior is not only undesirable, it is a potential security issue because any code with access to the CompletionStage can append additional work in the form of a dependent stage that will, provided the parent stage hasn't completed yet, be able to run under the prior action's security context.
Solving this problem will require a CompletionStage with awareness of managed executors which can more properly interface with them. Given the applicability of this same issue beyond JAX-RS (this pattern can arise in general usage as well), I'm recommending that we try to solve it within the EE Concurrency Utilities spec, by adding the ability on ManagedExecutorService to create CompletionStages that are backed by the ManagedExecutorService as the default asynchronous execution facility and which propagate thread context in a well-defined manner: by always capturing it from the thread that creates the CompletionStage, whether created as the initial stage from the ManagedExecutorService or created as a dependent stage.
I'd start out by proposing that ManagedExecutorService be given equivalents to the static methods that CompletableFuture has (except as non-static for ManagedExecutorService):
Having just finished writing this up, I checked the thread in the JAX-RS expert group again, and there is also the suggestion that EE Concurrency spec could provide a ManagedCompetableFuture, which is also an excellent suggestion. It's basically the same as above except that the methods would be static, accept a ManagedExecutorService as an argument, and return ManagedCompletableFuture. Either of these solutions would solve the problem.
The text was updated successfully, but these errors were encountered: