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

Random cron #944

Merged
merged 2 commits into from
Sep 13, 2023
Merged

Random cron #944

merged 2 commits into from
Sep 13, 2023

Conversation

MarcelWaldvogel
Copy link
Contributor

To avoid race conditions, run cron twice a day to make sure certificates are guaranteed to be renewed at least once during the last 24 hours of the certificate lifetime.

@MarcelWaldvogel
Copy link
Contributor Author

Also distribute load on letsencrypt servers better over the course of the day

@jprenken
Copy link

jprenken commented Oct 6, 2020

Ping @Neilpang - We at Let's Encrypt would love to see this PR updated and merged. Thanks! ❤️

@MarcelWaldvogel
Copy link
Contributor Author

Hey, someone is still looking at this old PR, wow!

I guess my explanation why we would need to run it twice per day is not valid, as the renewal starts several days (30, I believe) prior to the expiration.

However, having two points in time can help distribute the load better, under some assumptions. In any case, it should not be detrimental.

@jprenken: Do you see peaks at the beginning of each minute? I.e., should the --cron option include a random delay of [0,60] seconds?

The hour for the cron job isn't really random (as is the minute),
but assuming acme.sh installation times are not correlated, neither
will be the resulting cron start times.
@MarcelWaldvogel
Copy link
Contributor Author

I redid this based on the current code base, at the same time reducing clustering of cron start times.

Adapted test cases to allow for an hour != 0 with acmesh-official/acmetest#11

@jprenken
Copy link

@jprenken: Do you see peaks at the beginning of each minute? I.e., should the --cron option include a random delay of [0,60] seconds?

Thanks so much for updating this! Yes, we do see peaks at the beginning of minutes and even seconds; the finer-grained time randomization, the better.

@Eagle3386
Copy link
Contributor

Eagle3386 commented Sep 7, 2023

@Neilpang It's more than 6 years that this PR was opened, its changes are rather trivial & no merge conflicts - even after all these years - exists.

Would you mind considering to merge it in the near future, please? 😍

@Neilpang Neilpang merged commit 0c8870c into acmesh-official:dev Sep 13, 2023
oittaa added a commit to oittaa/acme.sh that referenced this pull request Jul 20, 2024
acmesh-official#944 (comment)

Let's Encrypt employee said in the comments "we do see peaks at the beginning of minutes and even seconds; the finer-grained time randomization, the better."

This adds a random amount of sleep second before beginning the cron job. I considered reading from `/dev/urandom` and so on, but we aren't doing anything security critical here so I thought that just using the process number modulo 59 (the largest prime <= 60) should give decent variability across the systems. The starting hour and minute are already randomized during the installation.
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.

4 participants