Skip to content

Fix sync server deadlock v1.2.0#439

Open
AndrushaUt wants to merge 6 commits intoplotly:masterfrom
AndrushaUt:fix-sync-server-deadlock-v1.2.0
Open

Fix sync server deadlock v1.2.0#439
AndrushaUt wants to merge 6 commits intoplotly:masterfrom
AndrushaUt:fix-sync-server-deadlock-v1.2.0

Conversation

@AndrushaUt
Copy link
Copy Markdown

…access

The shared _return_queue causes a race condition when multiple threads call to_image concurrently: task_queue.join() unblocks all waiters when the count hits zero, not when a specific task completes. Two threads race to return_queue.get(), one wins, the other blocks forever.

Fix: give each caller its own Queue embedded in the Task. The server routes the result directly into it. No sharing, no race, no deadlock.

Reproduces ~1/1000 calls with 64 threads.
See plotly/plotly.py#5549

Andrew Utkin and others added 6 commits April 1, 2026 10:50
…access

The shared _return_queue causes a race condition when multiple threads
call to_image concurrently: task_queue.join() unblocks all waiters when
the count hits zero, not when a specific task completes. Two threads
race to return_queue.get(), one wins, the other blocks forever.

Fix: give each caller its own Queue embedded in the Task. The server
routes the result directly into it. No sharing, no race, no deadlock.

Reproduces ~1/1000 calls with 64 threads.
See plotly/plotly.py#5549

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
oneshot_async_run creates a new thread + event loop per call, which can
also hang under load. Instead, auto-start the singleton server on first
sync call so all requests go through the thread-safe per-caller queue.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The server thread is daemon=True so it dies with the process.
The atexit close() calls thread.join() which hangs if Chromium
shutdown blocks.
@emilykl
Copy link
Copy Markdown
Collaborator

emilykl commented Apr 1, 2026

Hi @AndrushaUt, thanks for the PR.

Were you able to come up with a way to reliably reproduce plotly/plotly.py#5549 ? That would be helpful in reviewing this fix.

Could you also restore the deleted .github/workflows/ files and make sure your branch is up to date with master? Thanks!

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.

2 participants