| 631 | } |
| 632 | |
| 633 | apr_time_t md_job_delay_on_errors(md_job_t *job, int err_count, const char *last_problem) |
| 634 | { |
| 635 | apr_time_t delay = 0, max_delay = apr_time_from_sec(24*60*60); /* daily */ |
| 636 | unsigned char c; |
| 637 | |
| 638 | if (last_problem && md_acme_problem_is_input_related(last_problem)) { |
| 639 | /* If ACME server reported a problem and that problem indicates that our |
| 640 | * input values, e.g. our configuration, has something wrong, we always |
| 641 | * go to max delay as frequent retries are unlikely to resolve the situation. |
| 642 | * However, we should nevertheless retry daily, bc. it might be that there |
| 643 | * is a bug in the server. Unlikely, but... */ |
| 644 | delay = max_delay; |
| 645 | } |
| 646 | else if (err_count > 0) { |
| 647 | /* back off duration, depending on the errors we encounter in a row. |
| 648 | * As apr_time_t is signed, this might wrap around*/ |
| 649 | int i; |
| 650 | delay = job->min_delay; |
| 651 | for (i = 0; i < (err_count - 1); ++i) { |
| 652 | delay <<= 1; |
| 653 | if ((delay <= 0) || (delay > max_delay)) { |
| 654 | delay = max_delay; |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | if (delay > 0) { |
| 660 | /* jitter the delay by +/- 0-50%. |
| 661 | * Background: we see retries of jobs being too regular (e.g. all at midnight), |
| 662 | * possibly cumulating from many installations that restart their Apache at a |
| 663 | * fixed hour. This can contribute to an overload at the CA and a continuation |
| 664 | * of failure. |
| 665 | */ |
| 666 | md_rand_bytes(&c, sizeof(c), job->p); |
| 667 | delay += apr_time_from_sec((apr_time_sec(delay) * (c - 128)) / 256); |
| 668 | } |
| 669 | return delay; |
| 670 | } |
| 671 | |
| 672 | void md_job_end_run(md_job_t *job, md_result_t *result) |
| 673 | { |
no test coverage detected