Module: SSHKit::Backend::Netssh::DnsRetriable

Included in:
SSHKit::Backend::Netssh
Defined in:
lib/kamal/sshkit_with_ext.rb

Constant Summary collapse

DNS_RETRY_BASE =
0.1
DNS_RETRY_MAX =
2.0
DNS_RETRY_JITTER =
0.1
DNS_ERROR_MESSAGE =
/getaddrinfo|Temporary failure in name resolution|Name or service not known|nodename nor servname provided|No address associated|failed to look up|resolve/i

Instance Method Summary collapse

Instance Method Details

#with_dns_retry(hostname, retries: config.dns_retries, base: DNS_RETRY_BASE, max_sleep: DNS_RETRY_MAX, jitter: DNS_RETRY_JITTER) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kamal/sshkit_with_ext.rb', line 75

def with_dns_retry(hostname, retries: config.dns_retries, base: DNS_RETRY_BASE, max_sleep: DNS_RETRY_MAX, jitter: DNS_RETRY_JITTER)
  attempts = 0
  begin
    attempts += 1
    yield
  rescue => error
    raise unless retryable_dns_error?(error) && attempts <= retries

    delay = dns_retry_sleep(attempts, base: base, jitter: jitter, max_sleep: max_sleep)
    SSHKit.config.output.warn("Retrying DNS for #{hostname} (attempt #{attempts}/#{retries}) in #{format("%0.2f", delay)}s: #{error.message}")
    sleep delay
    retry
  end
end