From df8673242e277e34fbeb6cbffcac66f2ed0f61cd Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 3 Jan 2019 09:24:04 -0600 Subject: [PATCH] Order current token balance inserts to prevent deadlock Fixes #1295 --- .../chain/import/runner/address/current_token_balances.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex b/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex index 737a224268..8eebf0c984 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex @@ -60,10 +60,13 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalances do when is_atom(repo) and is_list(changes_list) do on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0) + # order so that row ShareLocks are grabbed in a consistent order + ordered_changes_list = Enum.sort_by(changes_list, &{&1.address_hash, &1.token_contract_address_hash}) + {:ok, _} = Import.insert_changes_list( repo, - changes_list, + ordered_changes_list, conflict_target: ~w(address_hash token_contract_address_hash)a, on_conflict: on_conflict, for: CurrentTokenBalance,