Skip to content

API Client Initialization Fails with "fetch failed" Error During RPC Calls #6169

@Shogunnn22

Description

@Shogunnn22

I'm experiencing intermittent failures during Polkadot API client initialization in my App. The initialization process fails with "fetch failed" errors when making RPC calls like getRuntimeVersion or getBlockHash.

Environment

  • @polkadot/api version: 14.3.1
  • Node.js version: 18
  • Network: Polkadot (relay chain)

Code

const { ApiPromise, HttpProvider } = require("@polkadot/api");

~~~

class PolkadotApi {

    static create = async (config) => {
        const httpProvider = new HttpProvider(config.nodeUrl);
        config.api = await ApiPromise.create({ provider: httpProvider });
        return new PolkadotApi(config);
    }

~~~

Error Details

pattern1

WARN	2025-06-16 04:39:01        API/INIT: Api will be available in a limited mode since the provider does not support subscriptions
ERROR	2025-06-16 04:39:01        RPC-CORE: getRuntimeVersion(at?: BlockHash): RuntimeVersion:: fetch failed
ERROR	2025-06-16 04:39:01        API/INIT: Error: FATAL: Unable to initialize the API: fetch failed
    at ApiPromise.__internal__onProviderConnect (/var/task/node_modules/@polkadot/api/cjs/base/Init.js:386:27)

pattern2

WARN	2025-06-15 20:56:40        API/INIT: Api will be available in a limited mode since the provider does not support subscriptions
ERROR	2025-06-15 20:56:40        RPC-CORE: getRuntimeVersion(at?: BlockHash): RuntimeVersion:: fetch failed
ERROR	2025-06-15 20:56:40        API/INIT: Error: FATAL: Unable to initialize the API: fetch failed
    at ApiPromise.__internal__onProviderConnect (/var/task/node_modules/@polkadot/api/cjs/base/Init.js:386:27)
ERROR	2025-06-15 20:56:40        RPC-CORE: getBlockHash(blockNumber?: BlockNumber): BlockHash:: fetch failed
ERROR	2025-06-15 20:56:40        RPC-CORE: properties(): ChainProperties:: fetch failed
ERROR	2025-06-15 20:56:40        RPC-CORE: methods(): RpcMethods:: fetch failed
ERROR	2025-06-15 20:56:40        RPC-CORE: chain(): Text:: fetch failed

What Investigated

✅ Block integrity: The specific blocks being processed appear to be valid
✅ Infrastructure resources: Currency node instances show normal memory and disk usage
❌ Root cause: Still investigating the underlying network/RPC issue

Expected Behavior

API client should initialize successfully and be ready to process blockchain data.

Actual Behavior

Initialization fails with "fetch failed" errors, causing abnormal termination of the BlockHandler process.

Questions

  • Are there known issues with RPC call reliability during API initialization?
  • Should we implement retry logic specifically for initialization phase?
  • Are there recommended timeout or connection pool settings for serverless environments?
  • Could this be related to WebSocket connection handling in Lambda environments?
  • This appears to be an intermittent issue rather than a consistent failure, suggesting potential network connectivity or timing-related causes. Any recommendations on production-ready error handling patterns for @polkadot/api in serverless architectures would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions