Skip to content
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

fix(rate_limit): Set explicit TTL for set of open requests [SNS-1864] #3362

Merged
merged 3 commits into from
Nov 9, 2022

Conversation

untitaker
Copy link
Member

step to repro leak:

  1. add set items, but do not explicitly remove them. possible by killing
    processes while a query is running
  2. stop processing requests for a particular bucket. possible by
    deleting a project that receives queries. we maintain sets of open
    requests per-project, using
    class ObjectIDRateLimiterProcessor(LogicalQueryProcessor):

without 1), we would be deleting set items explicitly on context manager
exit. Empty sets are equivalent to deleted keys in Redis.

without 2), we would have an extremely limited number of possible values
for bucket, so the issue is practically nonexistent. but since we
maintain sets per "object id" it's possible for a user to produce new
redis keys without ttl by creating/deleting projects

without an explicit TTL, we will be leaking tiny sets over time.

step to repro leak:

1) add set items, but do not explicitly remove them. possible by killing
   processes while a query is running
2) stop processing requests for a particular bucket. possible by
   deleting a project that receives queries. we maintain sets of open
   requests per-project, using https://github.com/getsentry/snuba/blob/a9ef6c56594246d0182a2b07728d1446a10e881b/snuba/query/processors/logical/object_id_rate_limiter.py#L19

without 1), we would be deleting set items explicitly on context manager
exit. Empty sets are equivalent to deleted keys in Redis.

without 2), we would have an extremely limited number of possible values
for `bucket`, so the issue is practically nonexistent. but since we
maintain sets per "object id" it's possible for a user to produce new
redis keys without ttl by creating/deleting projects

without an explicit TTL, we will be leaking tiny sets over time.
@untitaker untitaker requested a review from a team as a code owner November 9, 2022 11:58
@untitaker untitaker changed the title fix(rate_limit): Set explicit TTL for set of open requests fix(rate_limit): Set explicit TTL for set of open requests [SNS-1864] Nov 9, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 9, 2022

Codecov Report

Base: 90.75% // Head: 90.75% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (709a5f7) compared to base (578f573).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head 709a5f7 differs from pull request most recent head 7c0f0e9. Consider uploading reports for the commit 7c0f0e9 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3362   +/-   ##
=======================================
  Coverage   90.75%   90.75%           
=======================================
  Files         704      704           
  Lines       32335    32344    +9     
=======================================
+ Hits        29345    29355   +10     
+ Misses       2990     2989    -1     
Impacted Files Coverage Δ
snuba/state/rate_limit.py 91.83% <100.00%> (+0.11%) ⬆️
tests/state/test_rate_limit.py 79.72% <100.00%> (+1.04%) ⬆️
snuba/query/parser/expressions.py 87.50% <0.00%> (+2.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@untitaker untitaker merged commit a4b0afd into master Nov 9, 2022
@untitaker untitaker deleted the fix/rate-limit-memory-leak branch November 9, 2022 14:56
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.

3 participants