Skip to content

Add semaphore support for limiting concurrent updates#1670

Merged
JrooTJunior merged 3 commits intodev-3.xfrom
bugfix/1658
Apr 12, 2025
Merged

Add semaphore support for limiting concurrent updates#1670
JrooTJunior merged 3 commits intodev-3.xfrom
bugfix/1658

Conversation

@JrooTJunior
Copy link
Member

Description

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.

Fixes #1658

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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.
@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Apr 10, 2025
@JrooTJunior JrooTJunior requested a review from Copilot April 10, 2025 01:06
@github-actions
Copy link

✔️ Changelog found.

Thank you for adding a description of the changes

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • CHANGES/1658.bugfix.rst: Language not supported
Comments suppressed due to low confidence (2)

tests/test_dispatcher/test_dispatcher.py:813

  • The docstring refers to 'concurrent_updates_limit', but the parameter is named 'tasks_concurrency_limit'. Please update the docstring for consistency.
"""Test that semaphore is created only when handle_as_tasks=True and concurrent_updates_limit is not None"""

aiogram/dispatcher/dispatcher.py:367

  • The comment references 'concurrent_updates_limit' which is inconsistent with the parameter name 'tasks_concurrency_limit'. Consider updating the comment to match the parameter name.
# Create a semaphore if concurrent_updates_limit is specified

@codecov
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (870d97c) to head (23b9e44).
Report is 1 commits behind head on dev-3.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1670   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          511       511           
  Lines        12536     12546   +10     
=========================================
+ Hits         12536     12546   +10     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
aiogram/dispatcher/dispatcher.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JrooTJunior JrooTJunior requested a review from Copilot April 10, 2025 01:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • CHANGES/1658.bugfix.rst: Language not supported

@JrooTJunior JrooTJunior merged commit da3e84d into dev-3.x Apr 12, 2025
2 checks passed
@JrooTJunior JrooTJunior deleted the bugfix/1658 branch August 31, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issue or PR for stable 3.x version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support batched update processing in polling

3 participants