-
Notifications
You must be signed in to change notification settings - Fork 8
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
Side effect entry can be overtaken if not awaited #197
Comments
Reproducer:
Another potential fix is to "reserve/claim journal index", then re-order them in the sdk connection layer before sending them to the runtime. |
Unassigned to myself for the time being. I opened two PRs with the relative approaches. |
In both the aforementioned approaches we need to change the signature of
When invoking ctx.awakeable(), you get back an |
The third approach we also discussed, that would not require changing the signature of
This is not a great solution though, as it's not type checked and you'll figure out this mistake only at runtime in specific cases... |
After careful consideration, I start leaning toward the third approach of simply forcing the user to await the side effect before invoking another Removing side effect retries won't ultimately solve the issueBy removing the side effect retries, we could go around the limitation of changing the signature of async function doSideEffectAndRetry(ctx: RestateContext) {
while() {
await ctx.sideEffect()...
// if fails
await ctx.sleep()
}
} Then invoking and awaiting it later: const p1 = doSideEffectAndRetry(ctx);
ctx.awakeable();
await p1; // the awakeable id can be wrong because some side effect/sleep entries might have interleaved it! So we're back at the same problem. Concurrency in general is not supportedIn principle you can change in the above example But some primitive concurrency is supportedWhat's special about side effects is that in the simpler case of concurrency that we claim to support it's easier to fall in trap, which is how I ended up opening this issue in the first place. The following code is safe: const p1 = ctx.call(...)
// Do other context stuff
await p1; While this code is not: const p1 = ctx.sideEffect(...)
// Do other context stuff
await p1; The difference lies in the fact that The alternatives
|
The SideEffect entry writing can be overtaken if the user doesn't await on the returned promise.
To fix that, we need to internally correctly serialize the operations on the SDK state machine.
The text was updated successfully, but these errors were encountered: