Add semaphore support for limiting concurrent updates

Introduce a semaphore-based mechanism to control the number of concurrent tasks in polling mode when `handle_as_tasks=True`. Added the `tasks_concurrency_limit` parameter to `start_polling()` and `run_polling()`, preventing potential memory exhaustion during high update loads.
This commit is contained in:
JRoot Junior 2025-04-10 04:04:47 +03:00
parent 25e9127db9
commit 23b9e441d7
No known key found for this signature in database
GPG key ID: 738964250D5FF6E2
3 changed files with 211 additions and 3 deletions

6
CHANGES/1658.bugfix.rst Normal file
View file

@ -0,0 +1,6 @@
Fix memory exhaustion in polling mode with concurrent updates.
Added a semaphore-based solution to limit the number of concurrent tasks when using :code:`handle_as_tasks=True` in polling mode.
This prevents Out of Memory (OOM) errors in memory-limited containers when there's a large queue of updates to process.
You can now control the maximum number of concurrent updates with the new :code:`tasks_concurrency_limit`
parameter in :code:`start_polling()` and :code:`run_polling()` methods.