Skip to content

Duplicated job execution for single job instance. #3788

Closed
@Ceglee

Description

@Ceglee

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.

image

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions