BATCH-2442: fix infinite loop when item processor fails during a scan
Currently, when the processor throws an exception during a scan, the chunk is never marked as complete and the step never finishes. Moreover, items that were processed unsuccessfully are still written. This commit fixes the issue by excluding failed items from the scan. Resolves BATCH-2442
This commit is contained in:
committed by
Michael Minella
parent
fa54236f4d
commit
346dcce787
@@ -16,8 +16,16 @@
|
||||
|
||||
package org.springframework.batch.core.step.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.NonSkippableProcessException;
|
||||
@@ -35,13 +43,6 @@ import org.springframework.retry.RetryContext;
|
||||
import org.springframework.retry.RetryException;
|
||||
import org.springframework.retry.support.DefaultRetryState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* FaultTolerant implementation of the {@link ChunkProcessor} interface, that
|
||||
* allows for skipping or retry of items that cause exceptions during writing.
|
||||
@@ -572,6 +573,14 @@ public class FaultTolerantChunkProcessor<I, O> extends SimpleChunkProcessor<I, O
|
||||
Chunk<I>.ChunkIterator inputIterator = inputs.iterator();
|
||||
Chunk<O>.ChunkIterator outputIterator = outputs.iterator();
|
||||
|
||||
//BATCH-2442 : do not scan skipped items
|
||||
if (!inputs.getSkips().isEmpty()) {
|
||||
if (outputIterator.hasNext()) {
|
||||
outputIterator.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<O> items = Collections.singletonList(outputIterator.next());
|
||||
inputIterator.next();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user