Skip to content

Commit b251512

Browse files
committed
Fix error propagation from job executions
Before this commit, Spring Batch was catching all Throwable types so they can be available after the job execution through jobExecution.getAllFailureExceptions(). However, this prevents the JVM to crash on any Error like it should (for example like OOM errors [1]), effectively preventing the possibility to generate heap dumps to analyze these kinds of errors. This commit updates the code to catch only exceptions and let errors bubble up to let the JVM handle them as needed. Resolves #808 [1]: https://stackoverflow.com/questions/54811702/spring-batch-doesnt-propagate-errors (cherry picked from commit 7f375c6)
1 parent d4aa9e9 commit b251512

File tree

1 file changed

+5
-10
lines changed
  • spring-batch-core/src/main/java/org/springframework/batch/core/job

1 file changed

+5
-10
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.springframework.batch.core.repository.JobRestartException;
5656
import org.springframework.batch.core.scope.context.JobSynchronizationManager;
5757
import org.springframework.batch.core.step.StepLocator;
58-
import org.springframework.batch.repeat.RepeatException;
5958
import org.springframework.beans.factory.BeanNameAware;
6059
import org.springframework.beans.factory.InitializingBean;
6160
import org.springframework.lang.Nullable;
@@ -303,15 +302,11 @@ public final void execute(JobExecution execution) {
303302

304303
listener.beforeJob(execution);
305304

306-
try {
307-
doExecute(execution);
308-
if (logger.isDebugEnabled()) {
309-
logger.debug("Job execution complete: " + execution);
310-
}
311-
}
312-
catch (RepeatException e) {
313-
throw e.getCause();
305+
doExecute(execution);
306+
if (logger.isDebugEnabled()) {
307+
logger.debug("Job execution complete: " + execution);
314308
}
309+
315310
}
316311
else {
317312

@@ -337,7 +332,7 @@ public final void execute(JobExecution execution) {
337332
execution.setStatus(BatchStatus.max(BatchStatus.STOPPED, e.getStatus()));
338333
execution.addFailureException(e);
339334
}
340-
catch (Throwable t) {
335+
catch (Exception t) {
341336
logger.error("Encountered fatal error executing job", t);
342337
execution.setExitStatus(getDefaultExitStatusForFailure(t, execution));
343338
execution.setStatus(BatchStatus.FAILED);

0 commit comments

Comments
 (0)