Commit a236d4d
fix: return background task from consume_and_break_on_interrupt to prevent GC (#775)
# Description
ResultAggregator.consume_and_break_on_interrupt creates a background
asyncio.Task to continue consuming events after an interruption
(non-blocking or auth_required), but discards the task reference. On
Python 3.12+ the event loop only holds weak references to tasks, so the
garbage collector can silently collect the task before it completes —
dropping remaining events (completed/failed status) and push
notification callbacks.
Return the background task as a third tuple element so callers can hold
a strong reference. DefaultRequestHandler.on_message_send now tracks it
via _track_background_task(), the same mechanism already used for other
background work.
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- Important Prefixes for
[release-please](https://github.com/googleapis/release-please):
- `fix:` which represents bug fixes, and correlates to a
[SemVer](https://semver.org/) patch.
- `feat:` represents a new feature, and correlates to a SemVer minor.
- `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking
change (indicated by the `!`) and will result in a SemVer major.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
Fixes #774 🦕
---------
Co-authored-by: Ivan Shymko <ishymko@google.com>1 parent fa14dbf commit a236d4d
4 files changed
Lines changed: 39 additions & 7 deletions
File tree
- src/a2a/server
- request_handlers
- tasks
- tests/server
- request_handlers
- tasks
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
325 | 326 | | |
326 | 327 | | |
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
330 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
331 | 336 | | |
332 | 337 | | |
333 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
122 | 128 | | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
126 | 132 | | |
127 | 133 | | |
| 134 | + | |
128 | 135 | | |
129 | 136 | | |
130 | 137 | | |
131 | | - | |
| 138 | + | |
132 | 139 | | |
133 | 140 | | |
134 | 141 | | |
| |||
158 | 165 | | |
159 | 166 | | |
160 | 167 | | |
161 | | - | |
162 | | - | |
| 168 | + | |
| 169 | + | |
163 | 170 | | |
164 | 171 | | |
165 | 172 | | |
166 | 173 | | |
167 | | - | |
| 174 | + | |
168 | 175 | | |
169 | 176 | | |
170 | 177 | | |
| |||
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| 424 | + | |
424 | 425 | | |
425 | 426 | | |
426 | 427 | | |
| |||
520 | 521 | | |
521 | 522 | | |
522 | 523 | | |
| 524 | + | |
523 | 525 | | |
524 | 526 | | |
525 | 527 | | |
| |||
540 | 542 | | |
541 | 543 | | |
542 | 544 | | |
543 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
544 | 550 | | |
545 | 551 | | |
546 | 552 | | |
| |||
631 | 637 | | |
632 | 638 | | |
633 | 639 | | |
| 640 | + | |
634 | 641 | | |
635 | 642 | | |
636 | 643 | | |
| |||
689 | 696 | | |
690 | 697 | | |
691 | 698 | | |
| 699 | + | |
692 | 700 | | |
693 | 701 | | |
694 | 702 | | |
| |||
740 | 748 | | |
741 | 749 | | |
742 | 750 | | |
| 751 | + | |
743 | 752 | | |
744 | 753 | | |
745 | 754 | | |
| |||
950 | 959 | | |
951 | 960 | | |
952 | 961 | | |
| 962 | + | |
953 | 963 | | |
954 | 964 | | |
955 | 965 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| 238 | + | |
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
| |||
265 | 267 | | |
266 | 268 | | |
267 | 269 | | |
| 270 | + | |
268 | 271 | | |
269 | 272 | | |
270 | 273 | | |
271 | 274 | | |
272 | 275 | | |
273 | 276 | | |
| 277 | + | |
274 | 278 | | |
275 | 279 | | |
276 | 280 | | |
| |||
317 | 321 | | |
318 | 322 | | |
319 | 323 | | |
| 324 | + | |
320 | 325 | | |
321 | 326 | | |
322 | 327 | | |
323 | 328 | | |
324 | 329 | | |
325 | 330 | | |
| 331 | + | |
326 | 332 | | |
327 | 333 | | |
328 | 334 | | |
| |||
353 | 359 | | |
354 | 360 | | |
355 | 361 | | |
| 362 | + | |
356 | 363 | | |
357 | 364 | | |
358 | 365 | | |
359 | 366 | | |
360 | 367 | | |
361 | 368 | | |
362 | 369 | | |
| 370 | + | |
363 | 371 | | |
364 | 372 | | |
365 | 373 | | |
| |||
415 | 423 | | |
416 | 424 | | |
417 | 425 | | |
| 426 | + | |
418 | 427 | | |
419 | 428 | | |
420 | 429 | | |
421 | 430 | | |
422 | 431 | | |
423 | 432 | | |
| 433 | + | |
424 | 434 | | |
425 | 435 | | |
426 | 436 | | |
| |||
468 | 478 | | |
469 | 479 | | |
470 | 480 | | |
471 | | - | |
| 481 | + | |
472 | 482 | | |
473 | 483 | | |
474 | 484 | | |
| |||
0 commit comments