Repository navigation
Commit 0738739
fix(pybind): wait for in-flight SIGINT handlers before releasing the context
A process-directed SIGINT can run the handler on any thread, for example an
engine worker. If that handler had loaded the target ClientContext but not
yet called interrupt() when the main thread's query returned, the guard was
removed and the caller could drop the last reference to the connection (when
another thread had already closed it), so the store landed on freed memory.
The handler now counts itself in before loading the target and out after
interrupt(). The guard's destructor clears the target and then waits until
the count is zero, so a handler either is waited for or finds no target.
Each side stores one atomic and then loads the other, so the four operations
are explicitly sequentially consistent. The counter is lock-free and the
handler stays async-signal-safe.
The handler also sets the received flag and copies the previous handler
before counting itself out, so the wait covers those accesses as well and
the next guard does not reset them under a handler it waited for. Python's
chained handler is called outside the count, so the wait never depends on
code outside this file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 5b5f991 commit 0738739
1 file changed
Lines changed: 24 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
236 | 243 | | |
237 | 244 | | |
238 | 245 | | |
| |||
268 | 275 | | |
269 | 276 | | |
270 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
271 | 284 | | |
272 | | - | |
| 285 | + | |
| 286 | + | |
273 | 287 | | |
274 | 288 | | |
275 | 289 | | |
| 290 | + | |
| 291 | + | |
276 | 292 | | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
281 | 297 | | |
282 | 298 | | |
283 | 299 | | |
284 | 300 | | |
285 | 301 | | |
| 302 | + | |
286 | 303 | | |
287 | 304 | | |
| 305 | + | |
288 | 306 | | |
289 | 307 | | |
290 | 308 | | |
| |||
0 commit comments