Repository navigation
Conversation
MehmedGIT
marked this pull request as ready for review
October 13, 2026 08:43
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seems there are a few race conditions in different places due to the fact that the MongoDB is used as source of truth and there are multiple agents (processing server, processing workers, etc.) changing database entries asynchronously. Hence, the processing server needs its separate cache for locked pages and processing requests (coming from the
run_workflowmethod). The cache removes some race conditions, but other race conditions based on processing/workflow job states that are modified by different agents are still there.One of the many race conditions I faced is in the
run_workflow:The example above is now fixed by simply adding extra flags to the workflow jobs to track whether their submission is finished or not. There are also other flags for the processing job database entries to prevent any edge cases for the locking/unlocking
page_idsfor the workspace.The race conditions happen only when specific timing of the job submission and job processing are met. Which makes things even harder to detect without any locking mechanisms. Also keep in mind, that since the processing server also provides a way to chain processing jobs using the processing endpoint (and not
run_workflow) without having a specific workflow complicates things further. There are a few places where both endpoints need to be considered when using the similar methods to push/cache/queue jobs.I will first try to resolve as many potential race conditions as I can. That may include more caching on the processing server side, by also utilizing locking mechanisms here and there. However, using simply the database as a source of truth is not a good architectural solution overall. No matter what mechanisms I implement (and I have tried some more than what I committed here), there is always some kind of a race condition.
Another point is, even if the processing server is in a state to restart after a failure, there will be potential missing processing callbacks missed from the processing workers in the period when the processing server was trying to recover. On top, it is hard to track what requests are still inside the RabbitMQ after the processing server recovers. The processing server can keep track of what was pushed, and assume these records are in the RabbitMQ, but it is always uncertain how much was processed while the processing server was gone.
I am open to suggestions if you have any regarding the processing server and overall recovery. However, it seems nearly impossible to recover from a processing server failure. The better strategy would be to make sure the processing server is robust as it can be.
What does this PR add:
ocrd network client workflowcommandProcessing ServerProcessing Server:/user_workflow_callback_testDBWorkflowJobfor better tracking of job status and preventing duplicate actions:DBProcessorJobfor better tracking of job status and preventing duplicate actions:DBProcessorJobto prevent race conditions as much as possible by using the newly introduced variables in the database modelProcessing Serverto prevent race conditions leading to:Processing Server