Convert DBConnection.ConnectionError tcp recv: closed to {:error, :timeout}

Resolves #1251
pull/1252/head
Luke Imhoff 6 years ago
parent 5a3787da8b
commit 8e1bfc0589
  1. 8
      apps/explorer/lib/explorer/chain/import.ex
  2. 5
      apps/explorer/lib/explorer/repo.ex
  3. 13
      apps/indexer/lib/indexer/block/catchup/fetcher.ex
  4. 26
      apps/indexer/lib/indexer/block/realtime/fetcher.ex
  5. 11
      apps/indexer/lib/indexer/block/uncle/fetcher.ex

@ -53,7 +53,7 @@ defmodule Explorer.Chain.Import do
@type all_result :: @type all_result ::
{:ok, %{unquote_splicing(quoted_runner_imported)}} {:ok, %{unquote_splicing(quoted_runner_imported)}}
| {:error, [Changeset.t()]} | {:error, [Changeset.t()] | :timeout}
| {:error, step :: Ecto.Multi.name(), failed_value :: any(), | {:error, step :: Ecto.Multi.name(), failed_value :: any(),
changes_so_far :: %{optional(Ecto.Multi.name()) => any()}} changes_so_far :: %{optional(Ecto.Multi.name()) => any()}}
@ -334,6 +334,12 @@ defmodule Explorer.Chain.Import do
{:error, _, _, _} = error -> {:halt, error} {:error, _, _, _} = error -> {:halt, error}
end end
end) end)
rescue
exception in DBConnection.ConnectionError ->
case Exception.message(exception) do
"tcp recv: closed" <> _ -> {:error, :timeout}
_ -> reraise exception, __STACKTRACE__
end
end end
defp import_transaction(multi, options) when is_map(options) do defp import_transaction(multi, options) when is_map(options) do

@ -54,6 +54,9 @@ defmodule Explorer.Repo do
to_string(kind), to_string(kind),
" using options because of error.\n", " using options because of error.\n",
"\n", "\n",
"Chunk Size: ",
chunk |> length() |> to_string(),
"\n",
"Chunk:\n", "Chunk:\n",
"\n", "\n",
inspect(chunk, limit: :infinity, printable_limit: :infinity), inspect(chunk, limit: :infinity, printable_limit: :infinity),
@ -66,7 +69,7 @@ defmodule Explorer.Repo do
"\n", "\n",
"Exception:\n", "Exception:\n",
"\n", "\n",
Exception.format(:error, exception) Exception.format(:error, exception, __STACKTRACE__)
] ]
end) end)

@ -187,10 +187,15 @@ defmodule Indexer.Block.Catchup.Fetcher do
{:ok, inserted: inserted} {:ok, inserted: inserted}
{:error, {:import, [%Changeset{} | _] = changesets}} = error -> {:error, {:import = step, [%Changeset{} | _] = changesets}} = error ->
Logger.error(fn -> Logger.error(fn -> ["failed to validate: ", inspect(changesets), ". Retrying."] end, step: step)
["failed to validate: ", inspect(changesets), ". Retrying."]
end) push_back(sequence, range)
error
{:error, {:import = step, reason}} = error ->
Logger.error(fn -> [inspect(reason), ". Retrying."] end, step: step)
push_back(sequence, range) push_back(sequence, range)

@ -198,7 +198,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
] ]
end) end)
{:error, {:import, [%Changeset{} | _] = changesets}} -> {:error, {:import = step, [%Changeset{} | _] = changesets}} ->
params = %{ params = %{
changesets: changesets, changesets: changesets,
block_number_to_fetch: block_number_to_fetch, block_number_to_fetch: block_number_to_fetch,
@ -207,17 +207,23 @@ defmodule Indexer.Block.Realtime.Fetcher do
} }
if retry_fetch_and_import_block(params) == :ignore do if retry_fetch_and_import_block(params) == :ignore do
Logger.error(fn -> Logger.error(
[ fn ->
"failed to validate for block ", [
to_string(block_number_to_fetch), "failed to validate for block ",
": ", to_string(block_number_to_fetch),
inspect(changesets), ": ",
". Block will be retried by catchup indexer." inspect(changesets),
] ". Block will be retried by catchup indexer."
end) ]
end,
step: step
)
end end
{:error, {:import = step, reason}} ->
Logger.error(fn -> inspect(reason) end, step: step)
{:error, {step, reason}} -> {:error, {step, reason}} ->
Logger.error( Logger.error(
fn -> fn ->

@ -8,6 +8,7 @@ defmodule Indexer.Block.Uncle.Fetcher do
require Logger require Logger
alias Ecto.Changeset
alias EthereumJSONRPC.Blocks alias EthereumJSONRPC.Blocks
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.Hash alias Explorer.Chain.Hash
@ -118,6 +119,16 @@ defmodule Indexer.Block.Uncle.Fetcher do
{:ok, _} -> {:ok, _} ->
retry(errors) retry(errors)
{:error, {:import = step, [%Changeset{} | _] = changesets}} ->
Logger.error(fn -> ["Failed to validate: ", inspect(changesets)] end, step: step)
{:retry, original_entries}
{:error, {:import = step, reason}} ->
Logger.error(fn -> inspect(reason) end, step: step)
{:retry, original_entries}
{:error, step, failed_value, _changes_so_far} -> {:error, step, failed_value, _changes_so_far} ->
Logger.error(fn -> ["failed to import: ", inspect(failed_value)] end, Logger.error(fn -> ["failed to import: ", inspect(failed_value)] end,
step: step, step: step,

Loading…
Cancel
Save