From 0fbf024c8c9aeac5d6e9598022ebab4f1aa1a6f4 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 30 Oct 2018 11:10:11 -0700 Subject: [PATCH] fix: improve retry logic on AccountInUse --- web3.js/src/util/send-and-confirm-transaction.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web3.js/src/util/send-and-confirm-transaction.js b/web3.js/src/util/send-and-confirm-transaction.js index e38e82c948..8ac80538ba 100644 --- a/web3.js/src/util/send-and-confirm-transaction.js +++ b/web3.js/src/util/send-and-confirm-transaction.js @@ -15,7 +15,7 @@ export async function sendAndConfirmTransaction( runtimeErrorOk: boolean = false ): Promise { - let sendRetries = 3; + let sendRetries = 10; for (;;) { const start = Date.now(); const signature = await connection.sendTransaction(from, transaction); @@ -44,6 +44,9 @@ export async function sendAndConfirmTransaction( if (status !== 'AccountInUse' || --sendRetries <= 0) { throw new Error(`Transaction ${signature} failed (${status})`); } + + // Retry in 0..100ms to try to avoid another collision + await sleep(Math.random() * 100); } }