Add state validation and interruption handling to AbstractProducer.run()#147
Merged
bernardladenthin merged 1 commit intomainfrom Mar 23, 2026
Merged
Conversation
…xecution Add two guards at the start of run(): (1) check shouldRun to handle the case where interrupt() is called before the executor thread starts, and (2) verify state is INITIALIZED to prevent producing keys without proper initialization. This fixes a sporadic IllegalStateException in ProducerOpenCL where the OpenCL context could be null if releaseProducer() ran before the executor thread started. https://claude.ai/code/session_017zaPZjBcrkXejsmU8h5F9r
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #147 +/- ##
============================================
+ Coverage 74.40% 74.54% +0.14%
- Complexity 559 562 +3
============================================
Files 84 84
Lines 2422 2428 +6
Branches 207 208 +1
============================================
+ Hits 1802 1810 +8
+ Misses 564 563 -1
+ Partials 56 55 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
This change adds defensive checks to the
AbstractProducer.run()method to validate the producer's state before execution and gracefully handle interruptions that occur before the producer starts running.Key Changes
INITIALIZEDstate before running. If not, anIllegalStateExceptionis thrown with a descriptive message.shouldRunflag). If interrupted, the producer logs an info message and sets its state toNOT_RUNNINGbefore returning early.run_notInitialized_illegalStateExceptionThrown(): Verifies that callingrun()without initialization throwsIllegalStateExceptionrun_interruptedBeforeStarted_stateSetToNotRunning(): Verifies that if a producer is interrupted before starting, it properly logs the event and transitions toNOT_RUNNINGstateImplementation Details
The validation checks are performed at the beginning of the
run()method before the main execution loop, ensuring that invalid states are caught early and the producer behaves predictably in edge cases.https://claude.ai/code/session_017zaPZjBcrkXejsmU8h5F9r