Commit f5426b1
Andrew Utkin
Fix deadlock in GlobalKaleidoServer under concurrent 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.
Additionally, `_sync` functions now auto-start the singleton server
instead of falling back to `oneshot_async_run`, which creates a new
thread and event loop per call and can also hang under load.
The `atexit` handler that called `close()` → `thread.join()` is removed
since the server thread is already `daemon=True` and will exit with the
process. The `join()` could hang if Chromium shutdown blocks.
Reproduces ~1/1000 calls with 64 threads.
See https://github.com/plotly/plotly.py/issues/55491 parent b021c3d commit f5426b1
2 files changed
Lines changed: 17 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
165 | 170 | | |
166 | 171 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 172 | + | |
| 173 | + | |
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 178 | + | |
| 179 | + | |
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 184 | + | |
| 185 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | | - | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | | - | |
| 39 | + | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
| |||
72 | 69 | | |
73 | 70 | | |
74 | 71 | | |
75 | | - | |
76 | 72 | | |
77 | 73 | | |
78 | | - | |
79 | | - | |
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
| |||
92 | 86 | | |
93 | 87 | | |
94 | 88 | | |
95 | | - | |
96 | 89 | | |
97 | 90 | | |
98 | 91 | | |
| |||
117 | 110 | | |
118 | 111 | | |
119 | 112 | | |
120 | | - | |
121 | | - | |
122 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
123 | 116 | | |
124 | 117 | | |
125 | 118 | | |
| |||
0 commit comments