Repository navigation
Commit 7dd98a5
committed
fix(observe): preserve asyncio.timeout awareness in async generator wrapper
The _ContextPreservedAsyncGeneratorWrapper was creating a fresh
asyncio.Task for every __anext__ call (via asyncio.create_task(
context=...)). This changed the task identity between generator
iterations, which silently broke asyncio.timeout / asyncio.timeout_at
because those context managers bind to asyncio.current_task() at
enter time and the bound task is already done by the next iteration.
Replace the asyncio.create_task wrapping with a token-based approach
that sets preserved contextvars directly on the current task. Context
vars are task-local so they survive generator suspension points without
changing the task identity. The same pattern is applied to aclose()
for consistency.
Closes langfuse/langfuse#133491 parent 58aee87 commit 7dd98a5
2 files changed
Lines changed: 73 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
694 | 694 | | |
695 | 695 | | |
696 | 696 | | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
697 | 704 | | |
698 | 705 | | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
710 | 715 | | |
711 | 716 | | |
712 | 717 | | |
| |||
716 | 721 | | |
717 | 722 | | |
718 | 723 | | |
719 | | - | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
720 | 731 | | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
732 | 736 | | |
733 | 737 | | |
734 | 738 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
276 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
280 | 279 | | |
281 | | - | |
282 | | - | |
283 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
284 | 302 | | |
285 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
286 | 306 | | |
287 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
288 | 315 | | |
289 | 316 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 317 | + | |
294 | 318 | | |
| 319 | + | |
| 320 | + | |
295 | 321 | | |
296 | 322 | | |
297 | 323 | | |
| |||
304 | 330 | | |
305 | 331 | | |
306 | 332 | | |
307 | | - | |
308 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
309 | 337 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
314 | 341 | | |
315 | 342 | | |
316 | 343 | | |
| |||
0 commit comments