Propagate step context to worker threads in ChunkTaskExecutorItemWriter#5400
Open
seonwooj0810 wants to merge 1 commit into
Open
Propagate step context to worker threads in ChunkTaskExecutorItemWriter#5400seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
ChunkTaskExecutorItemWriter submits chunk processing to a TaskExecutor, but did not register a StepContext on the worker thread. As a result, @StepScope beans accessed inside the delegate ChunkProcessor failed with ScopeNotActiveException, and DisposableBean destruction was skipped. Register the step execution with StepSynchronizationManager before the delegate handles the request, and close it in a finally block. This mirrors the fix applied to multi-threaded ChunkOrientedStep in spring-projects#5183. Resolves spring-projects#5398 Signed-off-by: Seonwoo Jung <laborlawseon@kap.kr>
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.
Summary
ChunkTaskExecutorItemWritersubmits chunk processing to aTaskExecutorbut did not register aStepContexton the worker thread. As a result,@StepScopebeans accessed from inside the delegateChunkProcessorfail withScopeNotActiveException, andDisposableBean.destroy()is skipped for step-scoped beans.This change registers the step execution with
StepSynchronizationManagerbefore the delegate handles the request, and closes it in afinallyblock — the same pattern applied to multi-threadedChunkOrientedStepin #5183 (see commit 5642911).Fixes #5398.
Changes
ChunkTaskExecutorItemWriter.write(Chunk): wrap the worker-thread callable inStepSynchronizationManager.register(stepExecution)/close().ChunkTaskExecutorItemWriterTests.stepContextIsPropagatedToWorkerThread— verifiesStepSynchronizationManager.getContext()returns the activeStepContextfrom inside the delegateChunkProcessor.Test plan
./mvnw -pl spring-batch-integration -am test— all 150 tests pass, including the new testmainwithout this fix (StepContext should be available on the worker thread) and passes with itChunkTaskExecutorItemWritertests unaffected