Comments (7)
I'm not 100% correct in prev comment: if you pass stub method to ZPromise
it will be the same as in temporalio/sdk-java#1489
So ZPromise
is safe for ordinary Scala lambdas, but for not for stubbed methods. For example you should not wrap child workflow invocations with ZPromise
from zio-temporal.
See also temporalio/sdk-java#1489
from zio-temporal.
@ricochet1k Thank you for reporting! I'll also try to reproduce the problem
from zio-temporal.
After little research I believe that temporalio/sdk-java#1489 is misleading.
isAsync
checks, if lambda passed to Async.function
is a stub
:
private static boolean isAsyncJava(Object func) {
SerializedLambda lambda = JavaLambdaUtils.toSerializedLambda(func);
Object target = JavaLambdaUtils.getTarget(lambda);
return target instanceof ActivityStub
|| target instanceof ChildWorkflowStub
|| target instanceof ExternalWorkflowStub
|| (target instanceof AsyncInternal.AsyncMarker
&& lambda.getImplMethodKind() == MethodHandleInfo.REF_invokeInterface);
}
specifically created by ActivityStub
, ChildWorkflowStub
, ExternalWorkflowStub
or AsyncInternal.AsyncMarker
itself.
In case of ZPromise
I do not think that Scala lambda passed to Async.function
expected to be async/stub
in Temporal terms (because they are pure thunks). So seems like temporalio/sdk-java#1489 is not applicable to ZPromise
implementation.
Explain why one should assume that isAsyncJava
should return true
for every Scala lambda, like () => Unit
?
from zio-temporal.
I believe a pure thunk is also not detected as an async stub invocation. While it will run asynchronously, it won't necessarily do so in the way that we expect. The consequence was thus (as I noted in temporalio/sdk-java#1489):
If the Async.function (or similar) methods is called in an attempt to dispatch a child workflow from a Scala class, it fails to properly detect the attempt to call a workflow method on a temporal stub, and instead falls back to submitting the function to a new workflow thread in
AsyncInternal
. As a result, we saw excessive threads being created and consumed in workers, eventually resulting inRejectedExectionException
being thrown from the underlying executor.
Specifically, it is this code in AsyncInternal#execute
that has a problem:
if (temporalStub) {
initAsyncInvocation();
try {
func.apply();
return getAsyncInvocationResult();
} catch (Exception e) {
return Workflow.newFailedPromise(Workflow.wrap(e));
} finally {
closeAsyncInvocation();
}
} else {
CompletablePromise<R> result = Workflow.newPromise();
WorkflowThread.newThread(
() -> {
try {
result.complete(func.apply());
} catch (Exception e) {
result.completeExceptionally(Workflow.wrap(e));
}
},
false);
return result;
}
}
That second branch results in a situation that can draw the exception under too much concurrency.
from zio-temporal.
Related Issues (11)
- Base website documentation HOT 1
- Is it possible you could add a license? HOT 2
- Add zio-temporal to ZIO Community Libraries HOT 3
- SLF4J messages when using default zio-logging backend HOT 2
- Improve WorkerFactory lifecycle management
- Cannot build project using zio-temporal HOT 4
- Apps generate exception when running from assembly JAR HOT 1
- Revisit error model HOT 3
- Having an activity with ZIO effect breaks type safety HOT 4
- Lib cannot load .proto files when using scalapb plugin thru Mill build tool HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zio-temporal.