Skip to content

server: defer python proxy finalize out of the garbage collector - #2210

Closed
SVilgelm wants to merge 1 commit into
koush:mainfrom
SVilgelm:server/python-rpc-finalize-deadlock
Closed

SVilgelm wants to merge 1 commit into
koush:mainfrom
SVilgelm:server/python-rpc-finalize-deadlock

Conversation

@SVilgelm

@SVilgelm SVilgelm commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Python plugins with a lot of proxy traffic (OpenCV motion detection across several cameras is the easy way to hit it) freeze every few minutes until the host's ping check restarts them. Proxy finalizers call send() directly, and the cyclic GC can run them on any allocation, including one inside send() while it holds the transport's non-reentrant write lock, so the event loop thread deadlocks on itself. The finalizer now only does the local bookkeeping and hands the finalize message to the event loop with call_soon_threadsafe. The remote already ignores a late finalize for a proxy it has since re-sent, since each send gets a new finalizer id. rpc-finalize-test.py reproduces the deadlock against the old code and passes with the fix.

A proxy finalizer could run inside send() while it held the transport's write lock and deadlock the plugin's event loop thread, which then failed the host ping and got the plugin restarted.

Assisted-by: Claude Opus 5.5
Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 07:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@koush

koush commented Nov 16, 2026

Copy link
Copy Markdown
Owner

would it be better to move the invocation of finalize itself onto the next tick, rather than immediately invoked? then you won't need this new onProxyCollected.

@koush koush closed this Nov 16, 2026
@SVilgelm
SVilgelm deleted the server/python-rpc-finalize-deadlock branch November 18, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants