Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Preventing the ot-names cycling bug #352
This PR is meant to solve the bug in #351
Since the effect of this bug is something that Discord will probably call "API abuse" (rapid API calls not triggered by user action), we should probably try to merge this soon.
Edit: I've found the root cause of the issue
The problem is that in this step:
seconds_to_sleep = (next_midnight - datetime.utcnow()).seconds
We truncrate the time delta needed to reach midnight down to the seconds, which means we "wake up" slightly before midnight (
from datetime import datetime, timedelta mn = datetime.utcnow().replace(microsecond=0, second=0, minute=0, hour=0) mn2 = mn + timedelta(days=1) delta_seconds = (mn2 - datetime.utcnow()).seconds delta_full = mn2 - datetime.utcnow() print(delta_full) print(delta_seconds) print(delta_full - timedelta(seconds=delta_seconds)) print(datetime.utcnow() + timedelta(seconds=delta_seconds))
To fix this, I'm now simply adding one second to the computed sleep time so we always go over midnight:
seconds_to_sleep = (next_midnight - datetime.utcnow()).seconds + 1
This now closes #351, as the bug was found and fixed.
To revert I usually do an interactive rebase since that is what I am familiar with, but
That being said I still wouldn't have bothered with cleaning up my suggestion since you were just going to scrap the entire thing anyway (and if you had already committed the clean-up but not pushed, you could have dropped the commit through an interactive rebase or other means).
I do think it should be squashed anyway since we went through three iterations of fixing this bug. I don't think it would be beneficial to anyone viewing the history to include those previous attempts.