From e4ba0861e53ea593cb83c645541110df725a725f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 4 Dec 2023 21:34:51 +0100 Subject: [PATCH] Retry also on certain connection errors. (#680) --- changelogs/fragments/680-acme-retry.yml | 2 ++ plugins/module_utils/acme/acme.py | 3 ++- plugins/module_utils/acme/errors.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/680-acme-retry.yml diff --git a/changelogs/fragments/680-acme-retry.yml b/changelogs/fragments/680-acme-retry.yml new file mode 100644 index 00000000..1a26a253 --- /dev/null +++ b/changelogs/fragments/680-acme-retry.yml @@ -0,0 +1,2 @@ +bugfixes: + - "acme_* modules - also retry requests in case of socket errors, bad status lines, and unknown connection errors; improve error messages in these cases (https://github.com/ansible-collections/community.crypto/issues/680)." diff --git a/plugins/module_utils/acme/acme.py b/plugins/module_utils/acme/acme.py index c054a52f..8122d998 100644 --- a/plugins/module_utils/acme/acme.py +++ b/plugins/module_utils/acme/acme.py @@ -55,7 +55,8 @@ else: IPADDRESS_IMPORT_ERROR = None -RETRY_STATUS_CODES = (408, 429, 503) +# -1 usually means connection problems +RETRY_STATUS_CODES = (-1, 408, 429, 503) def _decode_retry(module, response, info, retry_count): diff --git a/plugins/module_utils/acme/errors.py b/plugins/module_utils/acme/errors.py index 2d25defe..c6377465 100644 --- a/plugins/module_utils/acme/errors.py +++ b/plugins/module_utils/acme/errors.py @@ -100,6 +100,8 @@ class ACMEProtocolException(ModuleFailException): http_code=format_http_status(code), problem_code=content_json['status']) else: code = 'status {problem_code}'.format(problem_code=format_http_status(code)) + if code == -1 and info.get('msg'): + code += ' ({msg})'.format(msg=info['msg']) subproblems = content_json.pop('subproblems', None) add_msg = ' {problem}.'.format(problem=format_error_problem(content_json)) extras['problem'] = content_json @@ -114,6 +116,8 @@ class ACMEProtocolException(ModuleFailException): ) else: code = 'HTTP status {code}'.format(code=format_http_status(code)) + if code == -1 and info.get('msg'): + code += ' ({msg})'.format(msg=info['msg']) if content_json is not None: add_msg = ' The JSON error result: {content}'.format(content=content_json) elif content is not None: