api key sleep drift#443
Open
Dipro-cyber wants to merge 1 commit into
Open
Conversation
time.sleep() uses the monotonic clock which does not advance when a machine is suspended (e.g. a laptop going to sleep). This caused API key expiry time drift: collection workers would still wait the full original duration even after the machine woke up and the key had already reset. Adds a sleep_until(epoch) helper that uses wall clock time (time.time()) with periodic 60-second wakeups to check if the target time has passed. This also means workers will pick up newly added API keys within 60 seconds rather than waiting out the full original sleep duration. Fixes chaoss#410 Signed-off-by: Diptesh Roy <droy88333@gmail.com>
b0fc87d to
0aff114
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
time.sleep()uses the monotonic clock which does not advance when a machineis suspended (laptop sleep). This caused API key expiry drift — collection
workers would continue waiting the full original duration even after waking up,
even if the rate-limited key had already reset.
Adds a
sleep_until(epoch)helper that wakes up every 60 seconds to check theactual wall clock time (
time.time()), matching keyman's own wall-clock-basedkey expiry logic.
Bonus: workers will now also pick up newly added API keys within 60 seconds
of them being published to keyman, rather than waiting out the full sleep.
This PR fixes #410
Notes for Reviewers
Change is in
keyman/KeyClient.pyonly. Thesleep_untilfunction is placedat module level so it can potentially be reused elsewhere. The two
time.sleep(0.1)calls inexpire()andinvalidate()are tiny fixeddelays (not key-expiry waits) and were left unchanged.
Signed commits
Generative AI disclosure