spring-projects / spring-projects/spring-batch

Chunck Monitor always report a warn about restarting, even if restart is desactivated

Open
#4,640 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug description
I use a RepositoryItemReader in a multi-thread scope (with a task executor)
RepositoryItemReader is thread safe, and as documented I set up : .saveState(false) and manage my state in my own code.

Environment
Java 21
SpringBoot 3.3.0
SpringBatch 5.1.2
Hibernate 6.5.2

Steps to reproduce
Run my Job and the WARN logs are showed: ItemStream was opened in a different thread. Restart data could be compromised.

Expected behavior
No warn about state when save state is disabled.

Minimal Complete Reproducible example
Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.

My Step:

    @Bean(name = "snapshotAccountPositionStep")
    @JobScope
    public Step cobAccounts(JobRepository jobRepository,
                            PlatformTransactionManager transactionManager,
                            @Qualifier("batchThreadPool") TaskExecutor taskExecutor,
                            SnapshotAccountPositionProcessor processor,
                            @Qualifier("snapshotListener") SnapshotAccountPositionStepListener snapshotListener,
                            @Value("${job.skipLimit}") int skipLimit,
                            @Value("${job.chunkSize}") int chunkSize) {
        return new StepBuilder("snapshotAccountPositionStep", jobRepository)
                .<TSIDResult, String>chunk(chunkSize, transactionManager)
                .faultTolerant()
                .skip(JobErrorStepListener.JobProcessingException.class)
                .skipLimit(skipLimit)
                .taskExecutor(taskExecutor)
                .reader(workAccountReader(null, null, null))
                .processor(processor)
                .listener(snapshotListener)
                .listener(getPatchListener())
                .writer(accountWriter())
                .listener(getErrorListener(null, null))
                .build();
    }

My reader:

    @Bean
    @StepScope
    public RepositoryItemReader<TSIDResult> workAccountReader(CobAccountWorkRepository repository,
                                                                 @Value("${positionSnapshot.readerPageSize}") Integer readerPageSize,
                                                                 @Value("#{jobParameters['date']}") LocalDate date) {
        return new RepositoryItemReaderBuilder<TSIDResult>()
                .name("workAccountReader")
                .saveState(false)
                .repository(repository)
                .methodName("findByStatusInAndDate")
                .arguments(List.of(TO_DO, DONE), date)
                .sorts(Collections.singletonMap(date.ID, Sort.Direction.ASC))
                .pageSize(readerPageSize)
                .build();
    }
     // ChunkMonitor.java
     private ChunkMonitorData getData() {
		ChunkMonitorData data = holder.get();
		if (data == null) {
			if (streamsRegistered) {
				logger.warn("ItemStream was opened in a different thread.  Restart data could be compromised.");
			}
			data = new ChunkMonitorData(0, 0);
			holder.set(data);
		}
		return data;
	}

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 ChunkMonitor.java and its getData() method, then trace how streamsRegistered relates to the RepositoryItemReader configured with saveState(false). Reproduce the task-executor scenario if possible and inspect existing Spring Batch tests for chunk monitoring. Done means the warning is not emitted when restart state is disabled, while relevant restart warnings remain covered.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.