Skip to content

Write count is doubled in a remote chunking manager step (ChunkMessageChannelItemWriter) #5606

Closed

Description

@fmbenhassine

In a remote chunking manager step (a step whose item writer is a ChunkMessageChannelItemWriter), the write count of the step execution is twice the number of items written. This is the case for a manager step based on ChunkOrientedStep as well as for the TaskletStep created by RemoteChunkingManagerStepBuilder (see "Affected versions" below).

The write count is incremented twice for the same items:

  1. The manager step increments it as soon as ChunkMessageChannelItemWriter#write returns. ChunkOrientedStep does it by the chunk size (contribution.incrementWriteCount(chunk.size())), and FaultTolerantChunkProcessor, used by the TaskletStep created by RemoteChunkingManagerStepBuilder, does it by the number of outputs. At that point the chunk has only been sent to the workers.
  2. In ChunkMessageChannelItemWriter#afterStep, the contributions returned by the workers (which carry their own write counts) are applied with stepExecution.apply(contribution), which adds their write counts on top.

Reproduction

A manager step built with RemoteChunkingManagerBuilder, with a worker simulated by a ChunkProcessorChunkRequestHandler that writes all items:

ChunkOrientedStep<String, String> step = new RemoteChunkingManagerBuilder("managerStep", jobRepository)
	.inputChannel(inputChannel)
	.outputChannel(outputChannel)
	.<String, String>chunk(2)
	.reader(new ListItemReader<>(items))
	.transactionManager(transactionManager)
	.build();
step.execute(stepExecution);

Results on main (all runs COMPLETED, all items written exactly once by the worker):

items chunk size readCount expected writeCount actual writeCount
5 2 5 5 10
9 2 9 9 18
9 3 9 9 18

The actual write count was exactly twice the item count for every item count from 1 to 12 and for chunk sizes 2 and 3. The result is the same whether the worker increments the write count by hand or uses a DefaultChunkProcessor with an ItemWriter. The worker contributions sum to the number of items (e.g. 2+2+2+2+1 for 9 items with a chunk size of 2), so the extra count comes from the manager side.

Affected versions

Reproduced on main (6.1.0-SNAPSHOT) and on 6.0.x (6.0.6-SNAPSHOT).

RemoteChunkingManagerBuilder is new in 6.1, so on 6.0.x the same worker and the same item counts were run against two other manager steps, both giving exactly twice the item count (e.g. 10 for 5 items and 18 for 9 items with a chunk size of 2):

  • a TaskletStep created with RemoteChunkingManagerStepBuilder
  • a ChunkOrientedStep wired by hand with a ChunkMessageChannelItemWriter as the item writer

Versions before 6.0 have not been checked.

Possible fix

ChunkTaskExecutorItemWriter already handles the same situation: it resets the write count in afterStep before applying the contributions of the tasks. ChunkMessageChannelItemWriter#afterStep could do the same, so that the items are not counted as written on the manager side.

Note that the write count of a failed or partially processed chunk must reflect what the workers actually wrote, so the fix should keep the worker contributions as the source of truth.

Activity

  1. self-assigned this
    on Oct 16, 2026
  2. added
    status: for-internal-team
    on Oct 16, 2026
  3. added a commit that references this issue on Nov 3, 2026
  4. added this to the 6.1.0 milestone on Nov 3, 2026
  5. added a commit that references this issue on Nov 3, 2026
    dc65645
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: integrationstatus: for-internal-teamtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions