Skip to content

Fix throttling in matrix plugin#1352

Merged
caronc merged 2 commits intocaronc:masterfrom
wolfgesbro:fix-throttling-in-matrix-plugin
Jun 18, 2025
Merged

Fix throttling in matrix plugin#1352
caronc merged 2 commits intocaronc:masterfrom
wolfgesbro:fix-throttling-in-matrix-plugin

Conversation

@wolfgesbro
Copy link
Contributor

@wolfgesbro wolfgesbro commented Jun 16, 2025

Description:

Related issue (if applicable): -

I noticed that in our project the automatic throttling after hitting the Matrix login rate limit did not work. This is an issue for us as long as the Apprise Persistent Storage is not working for the apache-airflow-providers-apprise package (see apache/airflow#51102).

There is also - in a separate commit - a small fix for a warning log message which confused me.

Sorry, I do not have time to look into test coverage...

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@fix-throttling-in-matrix-plugin

# Test out the changes with deactivated Persistent Storage, by calling the following command multiple times in a row until you hit the login rate limit.
apprise  --storage-mode=memory -vvv -t "Test Title" -b "Test Message" \
  <apprise URL of a Matrix server with login rate limit>

With this PR, throttling works as expected:

...
2025-06-16 15:25:12,182 - DEBUG - Matrix POST URL: https://<your server>/_matrix/client/v3/login (cert_verify=True)
2025-06-16 15:25:12,182 - DEBUG - Matrix Payload: <...>
2025-06-16 15:25:12,940 - DEBUG - Matrix Response: code=429, b'{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":301339}'
2025-06-16 15:25:12,940 - WARNING - Matrix server requested we throttle back 301339ms; retries left 1.
2025-06-16 15:25:12,940 - DEBUG - Response Details:
b'{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":301339}'
2025-06-16 15:25:12,940 - DEBUG - Throttling forced for 301.339s...
2025-06-16 15:30:14,279 - DEBUG - Matrix POST URL: https://<your server>/_matrix/client/v3/login (cert_verify=True)
2025-06-16 15:30:14,279 - DEBUG - Matrix Payload: <...>
2025-06-16 15:30:14,702 - DEBUG - Matrix Response: code=200, <...>
2025-06-16 15:30:14,702 - DEBUG - Authenticated successfully with Matrix server.
...

Throttling works: We can log in with the first retry.

Without this PR:

...
2025-06-16 15:38:25,679 - DEBUG - Matrix POST URL: https://<your server>/_matrix/client/v3/login (cert_verify=True)
2025-06-16 15:38:25,679 - DEBUG - Matrix Payload: <...>
2025-06-16 15:38:26,195 - DEBUG - Matrix Response: code=429, <...>
2025-06-16 15:38:26,195 - WARNING - Matrix server requested we throttle back 174.511ms; retries left 1.
2025-06-16 15:38:26,196 - DEBUG - Response Details:
b'{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":174511}'
2025-06-16 15:38:26,196 - DEBUG - Matrix POST URL: https://<your server>/_matrix/client/v3/login (cert_verify=True)
2025-06-16 15:38:26,196 - DEBUG - Matrix Payload: <...>
2025-06-16 15:38:26,713 - DEBUG - Matrix Response: code=429, b'{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":173992}'
2025-06-16 15:38:26,713 - WARNING - Matrix server requested we throttle back 173.992ms; retries left 0.
2025-06-16 15:38:26,713 - DEBUG - Response Details:
b'{"errcode":"M_LIMIT_EXCEEDED","error":"Too Many Requests","retry_after_ms":173992}'
2025-06-16 15:38:26,713 - DEBUG - Throttling forced for 173.992s...
2025-06-16 15:41:20,706 - DEBUG - Matrix POST URL: https://<your server>/_matrix/client/v3/register (cert_verify=True)
2025-06-16 15:41:20,706 - DEBUG - Matrix Payload: <...>
2025-06-16 15:41:20,725 - DEBUG - Matrix Response: code=403, b'{"errcode":"M_FORBIDDEN","error":"Registration has been disabled"}'
2025-06-16 15:41:20,725 - WARNING - Failed to handshake with Matrix server: Unauthorized - Invalid Token., error=403.
2025-06-16 15:41:20,725 - DEBUG - Response Details:
b'{"errcode":"M_FORBIDDEN","error":"Registration has been disabled"}'

Note, how the first throttling does not work: We are asked to throttle for 174 seconds but immediately POST another login request, without waiting.

@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.38%. Comparing base (cf12873) to head (38db454).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1352   +/-   ##
=======================================
  Coverage   99.38%   99.38%           
=======================================
  Files         162      162           
  Lines       21159    21160    +1     
  Branches     3804     3804           
=======================================
+ Hits        21028    21029    +1     
  Misses        121      121           
  Partials       10       10           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@caronc caronc merged commit ce90151 into caronc:master Jun 18, 2025
13 checks passed
@caronc
Copy link
Owner

caronc commented Jun 18, 2025

Thank you! Merged 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants