Comments (3)
Based on the provided context, it appears that there is a race condition between the creation of a bookmark and the retrieval of that bookmark by the workflow service. The Thread.Sleep(2000);
is used as a workaround to ensure that the bookmark is created before the workflow service attempts to retrieve it.
To address this issue, you should ensure that the event publishing and bookmark creation are completed before the workflow service starts looking for bookmarks to resume. This could involve using synchronization mechanisms such as semaphores, mutexes, or other signaling constructs to coordinate between the activity that creates the bookmark and the service that processes the event and resumes the workflow.
Additionally, you may want to review the workflow's design to ensure that the event is not published before the bookmark is created, or to implement a retry mechanism in the workflow service that will keep checking for the bookmark for a certain period before giving up.
If the issue persists, you may need to delve deeper into the Elsa Workflow's internal mechanisms for creating and managing bookmarks, or reach out to the Elsa Workflow community for support.
Since the provided context does not include specific methods or properties to address this race condition directly, the above suggestions are based on general best practices for dealing with concurrency and timing issues in asynchronous systems.
This comment was generated by Glime.
from elsa-core.
The activity creates the bookmark before publishing the event.
The activity asynchronously publishes the event after creating the bookmark.
The service asynchronously receives the event published by the activity.
The BlockingCollection used in the example is already a sufficient synchronization mechanism.
from elsa-core.
Your analysis of the issue is spot on.
There are several ways to go about this:
- Use the
IWorkflowInbox
to deliver events, which will keep a copy of the event and automatically resume the bookmark as soon as it is persisted. However, there are issues with this architecture, specifically, the event now has to persist in the system for while, which leads to issues where events are processed multiple times. For this reason, this service will be deprecated as of 3.3. - Use
context.Defer(=>)
in your activity. This method accepts a lambda that gets called after bookmarks are actually persisted. The downside of this is that the "real" work to be done now happens during the first commit state only, and not directly as the activity executes. This may or may not be an issue in practice. The Defer method is introduced with 3.3. - Instead of persisting bookmarks during a commit state, we might consider storing bookmarks immediately as soon as the activity creates a bookmark. The reason we're not already doing so is to try and batch multiple bookmarks in the workflow execution context before hitting the database. However, this has the disadvantage of race conditions that you described in this issue.
Given that in typical scenarios, only one, or perhaps a handful, of activities create a bookmark, batching their persistence may be considered a premature optimization that is unnecessary and in fact can invite race conditions under certain circumstances as demonstrated here.
from elsa-core.
Related Issues (20)
- Third-Party Integration Activities HOT 1
- [CHORE] Configure CI/CD with Renovate Bot HOT 1
- Make `Newtonsoft.Json` private? HOT 1
- What is the best place to implement clean-up logic for ActivityExecutionContext HOT 1
- ELSA 3.1.3 Getting Error when i call get /workflow-definitions endpoint HOT 2
- [BUG] MassTransit DisableConsumers Fails to Properly Disable Consumers and Disables Necessary Consumers HOT 1
- [CHORE] Elsa 3.0 设计器中 Fork的属性Branches如何设置? HOT 1
- [ENH] Enable External Interaction with Publish Event and Event Activities HOT 1
- [BUG] FailedToConnect activity in SendHttpRequest is not executed HOT 3
- [BUG] Mixed Content block after deployed to kubernetes HOT 2
- [BUG] Duplicate executions when using the default scheduling provider in single-node environment HOT 2
- [ENH] Add File Download Capability to SendHttpRequest Activity HOT 1
- [BUG]An unhandled error has occurred. Reload HOT 2
- [BUG] ELSA 3.2 rc1 with latest studio. Null reference exception when editing JavaScript expressions HOT 3
- [CHORE] Is there an example of Elsa 3.0 implementing various activities in designer mode? Thank you.
- [BUG]Is there an example of Elsa 3.0 implementing various activities in designer mode? Thank you. HOT 2
- [BUG]在Elsa 3.1.3设计器中If活动为啥有一个属性Condition,却没有Then和Else属性? HOT 2
- [BUG]Why is the If activity in designer 3.1.3 only having the Condition attribute and not the Then and Else attributes? HOT 1
- [BUG] Elsa 3.1 Fork activity wrong status HOT 1
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 elsa-core.