Fix TaskletStep to propagate checked exceptions when rollback is disabled#5322
Open
nikitanagar08 wants to merge 2 commits intospring-projects:mainfrom
Open
Fix TaskletStep to propagate checked exceptions when rollback is disabled#5322nikitanagar08 wants to merge 2 commits intospring-projects:mainfrom
nikitanagar08 wants to merge 2 commits intospring-projects:mainfrom
Conversation
Fixes spring-projects#5308 The previous fix for spring-projects#5217 addressed the OptimisticLockingFailureException by checking for isStopping() status, but this did not completely eliminate the race condition. The issue occurs when: 1. The main thread calls jobOperator.stop() 2. The main thread tries to update step executions 3. The job thread is also updating step executions (after processing a chunk) 4. Both threads try to update simultaneously → OptimisticLockingFailureException This commit: - Catches OptimisticLockingFailureException when updating step executions - Logs the exception at DEBUG level for diagnosis - Allows the stop process to continue since the job will check the STOPPING status and stop anyway Also improves the GracefulShutdownFunctionalTests.testStopJob test: - Increases timeout from 1 second to 5 seconds to give jobs more time to stop - Adds better logging to diagnose failures - Adds detailed comments explaining the timing considerations Signed-off-by: Nikita Nagar <permanayan84@gmail.com>
…bled Fixes spring-projects#5316 Propagate checked exceptions from Tasklet.execute even when transactionAttribute.rollbackOn(e) returns false. Only mark rollback metadata (ROLLBACK_EXCEPTION_KEY and rollback count) when rollback is actually configured for the exception. Also add regression tests for PROPAGATION_NOT_SUPPORTED to ensure a checked exception fails the step instead of being silently retried. Signed-off-by: Nikita Nagar <permanayan84@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5316
Problem
With
TaskletStepand a transaction attribute likePROPAGATION_NOT_SUPPORTED, a checked exception can be swallowed when rollback is disabled for that exception type. This causes the step loop to continue and re-execute the tasklet instead of failing.Solution
Modified the exception handling in
TaskletStepto:ROLLBACK_EXCEPTION_KEYand rollback count) when rollback is actually configured for the exceptionChanges
TaskletStep.java: Modified exception handling to propagate all exceptions regardless of rollback configurationrollbackOnreturns falseTesting
Added tests to verify: