spring-projects / spring-projects/spring-batch

Multi-threaded Step job hangs if @StepScope bean cannot be created

Open
#3,948 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

has: minimal-example in: infrastructure type: bug
Dominant language
Java
Stars
3k
Forks
2.5k
Avg merge
6d 53m
Merged PRs (30d)
3

Description

If in a multi-threaded step a @StepScope bean cannot be created then the batch just hangs waiting in TaskExecutorRepeatTemplate#waitForResults L172.

In my batch I want to pass in the pool size as a job parameter to the TaskExecutor used in the step. If this parameter is missing or cannot be converted into an int, then an exception is added to the deferred list but the TaskExecutorRepeatTemplate thinks a result is still coming from the ResultQueueResultHolder.

Here is my task executor:

@Bean
@StepScope
public TaskExecutor taskExecutor(@Value("#{jobParameters['poolSize']}") int poolSize) {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(poolSize);
	executor.setMaxPoolSize(poolSize);
	return executor;
}

Here's a pull request demonstrating the problem:

https://github.com/Apress/def-guide-spring-batch/pull/13

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 at TaskExecutorRepeatTemplate#waitForResults around line 172 and trace how the deferred list and ResultQueueResultHolder interact when the @StepScope taskExecutor cannot be created. Reproduce the case with a missing or non-integer poolSize job parameter as shown in the issue and pull request; done means the step reports the creation or conversion exception instead of hanging while waiting for a result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.