-
Notifications
You must be signed in to change notification settings - Fork 6
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
Test expiration #11
Open
jmsanders
wants to merge
4
commits into
snok:main
Choose a base branch
from
jmsanders:jordan/expiry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test expiration #11
Commits on Dec 27, 2022
-
I don't think expiration works as intended (or at least as I would expect it to). The response keys are correctly expired, but nothing is ever removed from the idempotency keys set. This has two consequences: - once a response key expires, requests using the same idempotency key will return 409 forever - the idempotency keys set grows without bound Instead, I would expect expiration to also apply to the idempotency keys set. Once the expiration window has passed, a new request with the same idempotency key should issue a new request. This commit only introduces the tests without implementing a solution. For MemoryBackend, I'd propose storing the expiry alongside the idempotency key. For RedisBackend, I'd propose something along the lines of redis/redis#135 (comment) using a sorted set to purge expired idempotency keys. But I wanted to run the change by you before taking action on either approach.
Configuration menu - View commit details
-
Copy full SHA for 9057f07 - Browse repository at this point
Copy the full SHA 9057f07View commit details
Commits on Jan 4, 2023
-
Configuration menu - View commit details
-
Copy full SHA for e63463e - Browse repository at this point
Copy the full SHA e63463eView commit details -
Previously, idempotency keys were never being expired. This had two consequences: - once a response key expires, requests using the same idempotency key will return 409 forever - the idempotency keys set grows without bound There's a new `expire_idempotency_keys` abstract method that implementations of Backend are responsible for implementing. The middleware calls it on every request. For the Memory backend, we now store idempotency keys in a dict intead of a set. The value of each key is its expiration time. We then iterate over all of the items in the dict and remove the ones with an expiration earlier than the current time. This operation isn't very efficient because it iterates over the entire dict, but given that the Memory backend is only meant to be used in local testing, I don't think it's worth optimizing further. For the RedisBackend, we now store idempotency keys in a sortedset instead of a set. The "score" of each key is its expiration time. This matches the Redis project's official recommendation on how to expire items in a set: redis/redis#135 (comment) We then delete any items from the sorted set with a "score" lower than the current time. The Redis docs describe this a potentially slow operation: https://redis.io/commands/zremrangebyscore/ If we don't want to call this on every request, we could instead add some sort of random fuzzing to only occassionally call it. Or we could abandon using a sorted set entirely and just store the idempotency key as its own key in Redis using the standard Redis expiration functionality. This would mean each request would store potentially three keys (idempotency key, response key, status code key) instead of the current two (response key, status code key). Users who upgrade to a version of the library that includes this change will see a failure in Redis when it tries to use a sortedset operation on an existing set. At a minimum, this should be called out in a changelog. Additionally, we could change the default idempotency key name from `idempotency-key-keys` to something else to avoid a collision.
Configuration menu - View commit details
-
Copy full SHA for 1532b90 - Browse repository at this point
Copy the full SHA 1532b90View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3cb5445 - Browse repository at this point
Copy the full SHA 3cb5445View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.