Handle UnpicklingError during worker shutdown#3145
Open
pmontepagano wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3145 +/- ##
=============================================
+ Coverage 87.793% 87.845% +0.052%
=============================================
Files 105 105
Lines 8143 8145 +2
Branches 1290 1290
=============================================
+ Hits 7149 7155 +6
+ Misses 687 685 -2
+ Partials 307 305 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
themavik
reviewed
Mar 23, 2026
themavik
left a comment
There was a problem hiding this comment.
Treating pickle.UnpicklingError like KeyError in _sync_states matches a broken multiprocessing proxy during shutdown. nit: pickle is only imported for the exception type—a short note beside nosec keeps bandit from looking for loads().
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.
When SIGTERM arrives during a
_sync_states()call, Python's signal handler interrupts the blockingread()on the multiprocessing proxy connection. The shutdown handler then accesses the same connection (viaset_state()), and_ForkingPickler.loads()sees corrupt bytes from the interrupted read, raising_pickle.UnpicklingError.This adds
UnpicklingErrorto the existing exception handling in:WorkerProcess.terminate()— alongsideBrokenPipeError,ConnectionResetError,EOFErrorWorkerProcess.exit()— same tuple, for cleanup consistencyWorkerManager._sync_states()— alongsideKeyErrorThese follow the same pattern already used for other connection-related exceptions during shutdown.
Related: https://community.sanicframework.org/t/random-exceptions-with-workermanager/1154