Skip to content

Race Condition MapStepRegistry unregisterStepsFromJob and getStep #4981

@ThomasKrieger

Description

@ThomasKrieger

Bug description
calling unregisterStepsFromJob and getStep from two Threads in parallel can lead to a NullPointerException

Environment
Spring Batch Version 5.2.3
All Jdk Versions, I tried jdk 17 and 21

Steps to reproduce
Here is an example which can lead to this race condition:

StepRegistry registry = new MapStepRegistry();
registry.register("foo", List.of(new TaskletStep("first")));
Thread first = new Thread() {
	@Override
	public void run() {
		registry.unregisterStepsFromJob("foo");
	}
};
first.start();
try {
	registry.getStep("foo", "first");
}
catch (NoSuchJobException e) {
}

Expected behavior
getStep should either return the Step or throw a NoSuchJobException.

Minimal Complete Reproducible example
Failing Tests

I used vmlens to make the test execute all thread interlreavings and make the test reproducible

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions