I have a simple websocket set up to listen to logs. It works, but then when I try to send over the transaction signature to a connection object to parse the instructions from it, it errors out after 30 minutes or so like this:

Error fetching transaction: TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ClientBrowser.callServer (/usr/src/app/node_modules/@solana/web3.js/lib/index.cjs.js:4901:17) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:6625:28)
      at node:internal/deps/undici/undici:6583:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:6614:13)
      at process.processImmediate (node:internal/timers:471:21) {

Here is the code snippet that I am trying to parse it in:

async function fetchTransactionInfo(txHash) {
  let retryAttempts = 5;
  let transaction;

  while (retryAttempts > 0) {
    try {
      const connection = new Connection(HTTP_ENDPOINT, {
        httpAgent: false,
        confirmTransactionInitialTimeout: 240000
      transaction = await connection.getParsedTransaction(txHash, {
        maxSupportedTransactionVersion: 0,
        finalized: true
      if (transaction) {
        break; // If the transaction is fetched successfully, exit the loop
    } catch (error) {
      console.error('Error fetching transaction:', txHash + ' ' + error);
      if (retryAttempts === 0) {
        console.error('Failed to fetch transaction after retries:', txHash);
        throw new Error('Failed to fetch transaction after retries: ' + txHash);
      console.log(`Retrying... attempts left: ${retryAttempts}`);
      await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait for 10 seconds before retrying

  if (!transaction) {
    console.error('Failed to fetch transaction:', txHash);
    return {};
... rest of logic

This fetchTransactionInfo function is basically being called every few minutes or so with a different transaction signature by my code. It's fine as a standalone script, but when I leave this running on a server for a while it starts giving the UND_ERR_CONNECT_TIMEOUT error. So I was wondering if anyone had similar issues and how did they resolve them?

For additional context, I have tried different kinds of connection configs, e.g. Connection(HTTP_ENDPOINT), Connection(HTTP_ENDPOINT, {httpAgent: false}), etc. But they don't really show much of a difference. Would appreciate any guidance on this matter!

In addition, I have tried exponential backoffs with my retries but they don't change the outcome, even if I throw in different RPC url's for each attempt at creating a new Connection object.

  • Are you using the public solana endpoints? These have heavy rate limits on socket connections.
    – Jonas H.
    Feb 18 at 19:53
  • I have used both public and private solana endpoints and these still give the same issues. It's not really a rate limit issue because I only pass transactions to be parsed like once every 5 minutes?
    – Jchpto
    Feb 19 at 3:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.