spring-projects / spring-projects/spring-batch

Partitioned Step execution not saved properly in production job with Spring Batch 5.2.x (works in 5.1.3)

Open
#5,019 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: feedback-provided type: bug
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

Bug description

This issue is the same as discussion #4683, but with additional details and version isolation. Currently I am on spring boot 3.5.6 and the issue occurs only with Spring Batch 5.2.x (e.g., 5.2.3). When using Spring Batch 5.1.3 (explicitly set via <spring-batch.version> with Spring Boot 3.5.6), the problem does not occur. By default, Spring Boot 3.5.6 pulled Spring Batch 5.2.3, which triggers the failure. This confirms the issue is related to changes in Spring Batch after 5.1.3.

Additional debugging details

Through debugging, I found that the class org.springframework.batch.core.repository.dao.JdbcStepExecutionDao fails to properly save a particular step to the database which was being routed through the method public void saveStepExecutions(final Collection<StepExecution> stepExecutions).
The count variable on line 284 of JdbcStepExecutionDao is set to 0 for the faulty step, and after several more method calls, the following error occurs:

org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0

The faulty step eventually gets saved with version 0, but it is expected to be 3 (as seen in a recreated scenario for Spring Batch 5.1.3).
Other steps that were saved via public void saveStepExecution(StepExecution stepExecution) worked fine.

Database and environment

  • Database: PostgreSQL 42.7.7
  • Backend: Spring Boot 3.5.6

Environment

  • Spring Batch: 5.2.x (confirmed failing)
  • Spring Batch: 5.1.3 (confirmed working)
  • Spring Boot: 3.5.6

Expected behavior
Job should not fail with EmptyResultDataAccessException when updating step status; should behave as in 5.1.3.

Please let me know if any further specific information is required.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with org.springframework.batch.core.repository.dao.JdbcStepExecutionDao, especially saveStepExecutions(Collection) and the reported count handling. Reproduce the partitioned job with Spring Batch 5.2.x and PostgreSQL, then compare it with 5.1.3. Done means the step is saved with the expected version and the job no longer raises EmptyResultDataAccessException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql, spring-boot
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.