-
Notifications
You must be signed in to change notification settings - Fork 148
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
WorkflowLocal shares initial value between all Workflows #1876
Comments
I took a crack at implementing a fix for this here: https://github.com/temporalio/sdk-java/compare/master...dano:sdk-java:fix-wflocal-caching?expand=1 It doesn't break any existing tests, and fixes the issue I'm seeing. If it seems like the right approach, I can clean up the tests a bit, add some additional comments, and open a PR. |
@dano Thanks for implementing a fix, thinking about it a bit more I think caching the result of |
@Quinn-With-Two-Ns do you mean that this test should pass? WorkflowLocal<AtomicInteger> wf = WorkflowLocal.withInitial(() -> new AtomicInteger(0));
assertNotSame(wf.get(), wf.get()); Meaning that repeatedly calling It's true that this matches the previous behavior of
Otherwise, you risk that the That said, it is true that adding caching behavior is a backwards compatibility break. If we must avoid that, even if we agree caching is better behavior, could we add a new factory that implements caching? Something like |
correct I agree with your points, but backwards compatibility it one of the most important parts of the SDK and we prioritize it above almost everything else. Adding an overload for caching or a different function is a backwards compatible change and that would be OK. |
Understood. I will update my branch to add a new API that uses the caching behavior and open a PR Would you consider deprecating the non-caching |
Yes I'd be open to deprecating the non-caching API. Note: we will probably never actually remove the API |
Reverted caching changes made to WorkflowLocal/WorkflowThreadLocal, which broke backwards compatibility and accidentally shared values between Workflows/Threads. Re-implemented caching as an optional feature, and deprecated the factory methods that created non-caching instances.
Reverted caching changes made to WorkflowLocal/WorkflowThreadLocal, which broke backwards compatibility and accidentally shared values between Workflows/Threads. Re-implemented caching as an optional feature, and deprecated the factory methods that created non-caching instances.
Thanks, @Quinn-With-Two-Ns. I've opened #1878. |
Reverted caching changes made to WorkflowLocal/WorkflowThreadLocal, which broke backwards compatibility and accidentally shared values between Workflows/Threads. Re-implemented caching as an optional feature, and deprecated the factory methods that created non-caching instances.
Reverted caching changes made to WorkflowLocal/WorkflowThreadLocal, which broke backwards compatibility and accidentally shared values between Workflows/Threads. Re-implemented caching as an optional feature, and deprecated the factory methods that created non-caching instances.
Reverted caching changes made to WorkflowLocal/WorkflowThreadLocal, which broke backwards compatibility and accidentally shared values between Workflows/Threads. Re-implemented caching as an optional feature, and deprecated the factory methods that created non-caching instances.
Thanks for merging the fix, @Quinn-With-Two-Ns. Do you have a rough idea of when a release that includes this fix will be made? |
Expected Behavior
If I create a
WorkflowLocal
viaWorkflowLocal.withInitial() -> new MyClass())
, I get a unique instance ofMyClass
the first time I callworkflowLocal.get()
in a given Workflow.Actual Behavior
I get the same instance of
MyClass
returned in every Workflow.Steps to Reproduce the Problem
This test demonstrates the issue:
This should print "bye" (which is the 1.19.1 behavior), but instead it prints "hi".
Specifications
The text was updated successfully, but these errors were encountered: