-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Duplicated job execution for single job instance. #3788
Comments
I think, in method |
I also encountered this problem with restartable job. ( Adding the guard condition
|
Any update on this issue. We still have similar issue. Also raised new issue with more details - #3966 |
The fixes have been released in v5.0.0. If you still have the issue, please add a comment here and we will re-open the issue for further investigation. |
Bug description
There is a chance, to have more than one actively running job executions, for a one job instance, which has restartable option set to false (preventRestart() being called).
Environment
4.2.1.RELEASE, Java 8u261, Oracle, 4 application instances running at the same time.
Steps to reproduce
Just create a job with single step, prevent it from restart and try to run it, in more than one java process at the same time. At some point you should be able to reproduce it.
Expected behavior
It should create only one job execution for each job instance.
Minimal Complete Reproducible example
You just have to configure any batch job, just be sure that you are using the same database for all processes.
Cause of the problem
Problem lies in SimpleJobRepository class in createJobExecution method. You are not checking there, whether job is restartable or not. You are only doing it at level of SimpleJobLauncher, which is calling createJobExecution, but this is not enough. You are setting proxy transaction only over the SimleJobRepository, so state in run method from SimpleJobLauncher might change.
Please take a look on following image. Assuming that processes (or even threads) will do it in following order and the 1 process will not yet start its job execution, job instance will end up with having two job executions.
Btw. in your documentation (https://docs.spring.io/spring-batch/docs/current/reference/html/schema-appendix.html) you are missing unique constraint in BATCH_JOB_INSTANCE definition.
The text was updated successfully, but these errors were encountered: