Fix SELECT on tables with bytea columns hanging in process worker#171
Merged
Maxteabag merged 1 commit intoMaxteabag:mainfrom Apr 18, 2026
Merged
Conversation
psycopg2 returns memoryview objects for bytea columns which cannot be pickled through multiprocessing.Pipe. The worker's send() silently swallowed the serialization error, leaving the client waiting forever. Convert memoryview to bytes in CursorBasedAdapter.execute_query() before rows are returned, so they can be safely pickled. Fixes Maxteabag#161
Owner
|
Thanks for the PR! |
Maxteabag
added a commit
that referenced
this pull request
Apr 18, 2026
#161's symptom was an indefinite spinner: psycopg2 returned memoryview for bytea, which couldn't be pickled across multiprocessing.Pipe. _WorkerState.send caught the exception and silently dropped it, so the client's recv() waited forever. #171 fixed the specific memoryview case at the adapter, but the silent swallow is still a trap for any other non-picklable cell type a future driver might return. Narrow the catch: on pickle errors, replace the payload with an error message (keyed to the original query id) so the client surfaces it. Tests pin the scenarios that were previously gaps: - CursorBasedAdapter.execute_query actually calls _sanitize_row (guards against a future revert of the call site). - Sanitized rows round-trip through pickle. - _WorkerState.send with a non-picklable payload delivers an error message within a short timeout. - Picklable payloads still pass through unchanged.
Contributor
Author
|
Thanks for merging! |
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
memoryviewobjects forbyteacolumns which cannot be pickled throughmultiprocessing.Pipesend()silently swallowed the serialization error, leaving the client waiting forever (spinner)memoryviewtobytesinCursorBasedAdapter.execute_query()before rows are returned, so they can be safely pickledTest plan
_sanitize_celland_sanitize_rowpassSELECT * FROM bytea_repro;as single statement — should return 3 rows immediatelySELECT id, name FROM bytea_repro;— should still workFixes #161