-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Dictionary Size changed during iteration" around application deployment time #446
Comments
If the blueprints have all been constructed (and decorated with any |
We are not using the I can't actually figure out WHERE the calls to YET, we see these errors in production. EditI see now that By the way, it's worth noting that we observe these errors on endpoints that both have and do not have Flask-Limiter decorators. I feel as though the problem is that the I'm now more convinced that we need a lock to protect access to Edit 2An alternative solution would be to drop |
Oh wow, I completely missed the |
Fix will be available in 3.7.0 |
Awesome! Already bumped on our end and deploying to production as we speak -- fingers crossed 🤞 |
@baydoun0 please close the issue if/when you've verified that it no longer exists in your environment! Thank you. |
I can confirm that this is no longer happening in production, so the bug is resolved! Thank you so much for fixing it this fast! |
Expected Behaviour
Flask Limiter should behave gracefully during application initialization.
Current Behaviour
About 50 times over the last couple of weeks, ever since we upgraded Flask Limiter to the latest version (we were on 1.x and now we're at 3.5.1), we consistently observe the following error on Sentry:
It happens around the time our application initializes after deployment.
Steps to Reproduce
I don't have concrete steps to reproduce for everyone, our application is in production under normal load, and we service quite a bit of requests, but for us, steps to reproduce are simply:
Concurrently, the application needs to be bombarded with requests.
Your Environment
We're also using Redis as a backing store.
Note: We are constructing all blueprints and attaching all routes to them, and also configuring ALL
before_request
andafter_request
hooks before initializing Flask Limiter in an attempt to mitigate this, but it's not working as expected. Flask Limiter seems to be kicking in immediately (which is fine, but it should handle the race condition better).Suggested Fix
The
self._blueprint_exemptions
field inside theLimitManager
class is only modified in one place: theadd_blueprint_exemption
method. All that needs to be done is to add a lock, and acquire it when attempting to write, or iterate overself._blueprint_exemptions
.The text was updated successfully, but these errors were encountered: