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
Fix termination of request context for non-blocking scheduled methods #27108
Conversation
...sions/scheduler/common/src/main/java/io/quarkus/scheduler/common/runtime/DefaultInvoker.java
Outdated
Show resolved
Hide resolved
39419ea
to
f249eb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, LGTM
A test would be nice though. It's easy to mess up this stuff with a refactoring. |
For sure. We'll need an integration test for this... |
By the way, the fix looks correct but I haven't run a test to check that it fixes the issue. I trust you on this. |
I did. But since CP is involved one can be never sure ;-). |
I will add a test shortly... |
In fact, the fix is probably wrong. Or at least does not cover all possible cases. I'm on it. |
f249eb2
to
ac9f4aa
Compare
49124e5
to
9cd048a
Compare
The PR should be ready for review now. I've modified the existing |
} finally { | ||
requestContext.terminate(); | ||
// Always deactivate the context | ||
requestContext.deactivate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is right?
The context could be deactivated before being used by invokeBean
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, deactivation means that we remove a threadlocal but do not destroy the context/beans, i.e. the thread is "clear". If Mutiny is used inside the invokeBean()
then we rely on context propagation to make a snapshot of the current context and propagate it accordingly.
It wouldn't work for CompletionStage
with a custom executor though. In this case, a user needs to handle the context propagation manually (as it was before).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct, CP takes snapshot based on the ContextState
of currently active context when it is captured. If I get this scenario right, then this will happen when you perform invokeBean()
.
...sions/scheduler/common/src/main/java/io/quarkus/scheduler/common/runtime/DefaultInvoker.java
Show resolved
Hide resolved
There's nothing in the javadoc of |
if the implementation of
Will everything still work when the validation fails? Maybe I'm missing something though. My review is only based on the code in the PR. |
In particular, I don't know when we have to deactivate or terminate the context and in which order these operations can run. |
The actual (generated) implementation of the public class NonBlockingScheduledMethodTest$_Jobs_ScheduledInvoker_everySecondUni_bc4773d4b48cf55d38fb70c74dd8ac9a99dcf2af
extends
DefaultInvoker {
public CompletionStage invokeBean(final ScheduledExecution scheduledExecution) throws Exception {
try {
final ArcContainer container = Arc.container();
return ((NonBlockingScheduledMethodTest$Jobs) container
.instance(container.bean("43b9ee810358bfaef695a734f2ffc1709e5a4cfb")).get()).everySecondUni()
.subscribeAsCompletionStage();
} catch (Throwable ex) {
return CompletableFuture.failedStage(ex);
}
}
public boolean isBlocking() {
return false;
}
} |
@manovotn pls could you review this one. Your knowledge of CDI and CP could be beneficial here. |
9cd048a
to
991c8a5
Compare
I've removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this way the context should get destroyed correctly.
- fix the problem mentioned in quarkusio#23739 (comment)
991c8a5
to
5ee7fe6
Compare
Nice, thanks! |
Hibernate Reactive Panache MSSQL Native Build #23739 (comment)