Skip to content

Commit

Permalink
Prevent uncaught errors in the send-retry loop from bubbling up uncaught
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Oct 12, 2024
1 parent ad5f2d8 commit f9da5a7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ping-thing-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { getNextSlot } from "./utils/slot.mjs";
import { setMaxListeners } from "events";
import axios from "axios";
import { createRecentSignatureConfirmationPromiseFactory } from "@solana/transaction-confirmation";
import { safeRace } from '@solana/promises';

dotenv.config();

Expand Down Expand Up @@ -122,9 +123,13 @@ async function pingThing() {

console.log(`Sending ${signature}`);

let rejectSendLoop;
const sendLoopPromise = new Promise((_, reject) => {
rejectSendLoop = reject;
});
let sendAbortController;
function sendTransaction() {
sendAbortController = new AbortController()
sendAbortController = new AbortController();
mSendTransactionWithoutConfirming(transactionSignedWithFeePayer, {
abortSignal: sendAbortController.signal,
commitment: COMMITMENT_LEVEL,
Expand All @@ -134,7 +139,7 @@ async function pingThing() {
if (e instanceof Error && e.name === 'AbortError') {
return;
} else {
throw e;
rejectSendLoop(e);
}
});
}
Expand All @@ -150,11 +155,14 @@ async function pingThing() {
});
txStart = Date.now();
sendTransaction();
await mConfirmRecentSignature({
abortSignal: pingAbortController.signal,
commitment: COMMITMENT_LEVEL,
signature,
});
await safeRace([
mConfirmRecentSignature({
abortSignal: pingAbortController.signal,
commitment: COMMITMENT_LEVEL,
signature,
}),
sendLoopPromise,
]);
console.log(`Confirmed tx ${signature}`);
} catch (e) {
// Log and loop if we get a bad blockhash.
Expand Down

0 comments on commit f9da5a7

Please sign in to comment.