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

Better dns resolver retries #1366

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/www.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ on:
branches:
- master
- "renovate/frontend/*"
paths:
- ".github/workflows/www.yaml"
- "www/**"
pull_request:
branches:
- "**"
paths:
- ".github/workflows/www.yaml"
- "www/**"
jobs:
build:
name: Build image
Expand Down
22 changes: 22 additions & 0 deletions apps/core/lib/core/retry.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule Core.Retry do
require Logger

defstruct [wait: 200, attempts: 0, max: 3]

def retry(fun, args) when is_function(fun) and (is_list(args) or is_map(args)) do
struct(__MODULE__, Map.new(args))
|> retry(fun)
end

def retry(%__MODULE__{attempts: attempts, max: max, wait: wait} = conf, fun) do
case {attempts < max, fun.()} do
{_, :ok} -> :ok
{_, {:ok, res}} -> {:ok, res}
{true, {:error, _} = error} ->
Logger.info "failed to execute function, error: #{inspect(error)}"
:timer.sleep(wait)
retry(%{conf | attempts: attempts + 1}, fun)
{_, {:error, err}} -> {:error, err}
end
end
end
18 changes: 13 additions & 5 deletions apps/core/lib/core/services/cloud/workflow/shared.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ defmodule Core.Services.Cloud.Workflow.Shared do
def sync(_), do: :ok

def up(%ConsoleInstance{status: :deployment_created, url: url} = inst) do
:timer.sleep(:timer.seconds(5))
case {DNS.resolve(url), DNS.resolve(url, :cname)} do
{{:ok, [_ | _]}, _} -> mark_provisioned(inst)
{_, {:ok, [_ | _]}} -> mark_provisioned(inst)
{{:error, err}, _} -> {:error, "cannot resolve #{url}: #{inspect(err)}"}
:timer.sleep(:timer.seconds(10))
Core.Retry.retry(fn ->
case {DNS.resolve(url), DNS.resolve(url, :cname)} do
{{:ok, [_ | _]}, _} -> mark_provisioned(inst)
{_, {:ok, [_ | _]}} -> mark_provisioned(inst)
{{:error, err}, _} -> {:error, "cannot resolve #{url}: #{inspect(err)}"}
end
end, wait: :timer.seconds(30), max: 4)
|> case do
{:ok, _} = res -> res
{:error, err} ->
Logger.info "failed to resolve dns, error: #{inspect(err)}, just going to mark anyways and assume it's a negative caching bug"
mark_provisioned(inst)
end
end

Expand Down
Loading