Commit 2983732
deadlock patch (#148)
Why
===
deadlock in the server-side reconnect case:
1. establish handshake acquires session lock:
https://github.com/replit/river-python/blob/6e2bc1ab1392f5a8407a08f6c8f049ec9e4b308d/src/replit_river/server_transport.py#L249
2. if there is a session mismatch, we close the old session:
https://github.com/replit/river-python/blob/6e2bc1ab1392f5a8407a08f6c8f049ec9e4b308d/src/replit_river/server_transport.py#L290
3. session.close calls _close_session_callback
https://github.com/replit/river-python/blob/6e2bc1ab1392f5a8407a08f6c8f049ec9e4b308d/src/replit_river/session.py#L299
4. _delete_session also tries to acquire the session lock
https://github.com/replit/river-python/blob/6e2bc1ab1392f5a8407a08f6c8f049ec9e4b308d/src/replit_river/server_transport.py#L316
What changed
============
1. dont need to call _delete_session as .close will already do that
2. lift out session close outside of session lock
3. in the handshake case, let the final call to get_or_create_session
replace the session and close the old one
Test plan
=========
added a test
Notes
=========
I have a draft of a more in-depth approach on [this
branch](https://github.com/replit/river-python/tree/jackyzha0/fix-deadlock)
which uses a lock-ownership-transfer based approach that should catch it
more generically but ran into ownership problems lol
Seeing as we are planning on migrating chat service to Node anyways so
we only have one River server implementation, we hopefully don't have to
maintain this surface for much longer 🤞
---------
Co-authored-by: Devon Stewart <[email protected]>1 parent 6e2bc1a commit 2983732
File tree
4 files changed
+39
-16
lines changed- src/replit_river
- tests
- river_fixtures
4 files changed
+39
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
370 | 369 | | |
371 | 370 | | |
372 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | | - | |
122 | | - | |
123 | | - | |
| 123 | + | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | 146 | | |
148 | 147 | | |
149 | 148 | | |
| |||
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
250 | | - | |
| 251 | + | |
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
| |||
285 | 286 | | |
286 | 287 | | |
287 | 288 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | 289 | | |
293 | 290 | | |
294 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
0 commit comments