JS HttpAgent.create timeout

Today I’m experiencing IC overload and it is a good opportunity to handle this in my apps.
But actually for the best user experience I’d like to display message after 10 seconds of waiting.
At this monent it throws errors after a very long peroid - many minutes. From user’s point of view it looks like frozen app.

I see there is some idle timeouts already but what about first connection timeout?

Most popular error message is:
Failed to load resource: net::ERR_CONNECTION_TIMED_OUT
icp-api.io/api/v2/canister/ryjl3-tyaaa-aaaaa-aaaba-cai/read_state:1

You can try to implement and pass a custom backoff strategy as backoffStrategy option while creating a HttpAgent instance.

The default strategy seems to have an exponential backoff with a timeout at 5 minutes, it can be found here: agent-js/packages/agent/src/polling/strategy.ts at main · dfinity/agent-js · GitHub

Thank you for response ! I’ll test it.

Word of warning: if you manually timeout your request after e.g. 10 seconds this does not necessarily mean that the request will not happen. If the agent retries (automatically, or manually if a user retries the failed operation) you may end up with duplicate transactions. In that case I would suggest that you use idempotency keys like the ledger’s created_at_time key

3 Likes

thank you for the information, I will remember about it.