adutra commented on PR #1758: URL: https://github.com/apache/polaris/pull/1758#issuecomment-2930889034
> The TaskExecutor was failing with error like ContextNotActiveException, the reason seems that CDI injection doesn't work well when the access is made outside the scoped, like background task, which is what TaskExecutor does That is correct and that is precisely why the following methods were created: * `org.apache.polaris.core.context.CallContext#copyOf` * `org.apache.polaris.core.PolarisCallContext#copyOf` It is also because of that that `CallContext.copyOf()` takes care of creating a copy of the current `RealmContext` _and_ of the current `PolarisCallContext`: https://github.com/apache/polaris/blob/ca99c53b9c5be9022b3f4960b0d998a0cc9a4b84/polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java#L95-L96 From that point onwards, it's 100% safe to use that instance of `RealmContext`, since it's _not_ a CDI bean. The instance returned by `PolarisCallContext.copyOf()` is also not a CDI-managed bean; however, we observe that it holds references to 4 beans: `BasePersistence`, `PolarisDiagnostics`, `PolarisConfigurationStore` and `Clock`: https://github.com/apache/polaris/blob/ff6440a80bdd146c057cad8776c35d1aa0d7081c/polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java#L63-L67 Of these 4 beans, 3 are application-scoped and should be usable in any thread: `PolarisDiagnostics`, `PolarisConfigurationStore` and `Clock`. As for `BasePersistence`, it's not a CDI bean and should be usable in any thread as well (I'll notice that @dimas-b added a `detach()` method to `BasePersistence` recently, which has no implementation for now but the default one that returns `this` – was it with the intent of creating non-CDI beans out of CDI ones?). Taking a step back: One _could_ argue here that we should rely on context propagation done by Quarkus. And yes, that was my first intention when I ported the `TaskExecutor` code to Quarkus. If you look at the default task executor: https://github.com/apache/polaris/blob/2e373e51ce5434c26635535b684ff210a53b1745/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java#L306-L313 You'll notice it's a `ManagedExecutor` with context propagation enabled. But unfortunately, `CallContext` is forcibly closed by a dispose method: https://github.com/apache/polaris/blob/2e373e51ce5434c26635535b684ff210a53b1745/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java#L141-L143 And my experimentations with Quarkus showed that in this case, the `CallContext` instance _is_ propagated to the `TaskExecutor` threads, but is also closed as soon as the initial HTTP request is done, leading to failures in the task executor threads. That was the reason why I switched to manual copies. FYI @dimas-b @gh-yzou -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org