From 83223f8e4c2001b61465509143e12fe9e862b3ea Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 24 Apr 2017 03:45:40 +0200 Subject: [PATCH] wg: retry name resolution on temporary failure This should solve many problems at init time. Signed-off-by: Jason A. Donenfeld --- src/config.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index be15870..c00e91c 100644 --- a/src/config.c +++ b/src/config.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -189,7 +190,15 @@ static inline bool parse_endpoint(struct sockaddr *endpoint, const char *value) *end = '\0'; ++end; } - ret = getaddrinfo(begin, end, &hints, &resolved); + + for (unsigned int timeout = 1000000; timeout < 90000000; timeout = timeout * 3 / 2) { + ret = getaddrinfo(begin, end, &hints, &resolved); + if (ret != EAI_AGAIN) + break; + fprintf(stderr, "%s: `%s`. Trying again in %.2f seconds...\n", gai_strerror(ret), value, timeout / 1000000.0); + usleep(timeout); + } + if (ret != 0) { free(mutable); fprintf(stderr, "%s: `%s`\n", gai_strerror(ret), value);