shopify-api-js icon indicating copy to clipboard operation
shopify-api-js copied to clipboard

Random ETIMEDOUT when making lots of graphql requests

Open tommypepsi opened this issue 2 years ago • 0 comments

Issue summary

I'm updating and creating lots of products with each of them having multiple request (creating the products, adding metafields and adding international price for each markets). I made a queue that handles respecting the available graphql points so I'm not hitting the throttle response by shopify. Somehow I seem to be randomly getting a timedout error after a couple hundreds of request.

At first I thought I was too greedy with my concurrent requests but setting the concurrent to 10, 5 or 2 all get the same result. It only seems to not happen when I only do one request at a time but this is definitely too slow.

I also tried adding "tries: 10" to my request but that doesn't seem to work, it still throws an error without retrying.

The only way I managed to make it work is by doing a try catch and retrying the request manually, then it seems to work the second time.

Expected behavior

Not sure if the error is an issue related to this library, if so I guess the expected behavior is to not get that error. Otherwise I would expect the tries option to actually retry the request but it doesn't seem to be the case.

Actual behavior

I get this error after a couple of request:

HttpRequestError: Failed to make Shopify HTTP request: FetchError: request to https://mystore.myshopify.com/admin/api/2022-04/graphql.json failed, reason: connect ETIMEDOUT 23.227.38.74:443
     at HttpRequestError.ShopifyError [as constructor] (C:\Users\.....\Documents\Code\Shopify\Apps\.....\node_modules\@shopify\shopify-api\dist\error.js:13:28)
     at new HttpRequestError (C:\Users\.....\Documents\Code\Shopify\Apps\.....\node_modules\@shopify\shopify-api\dist\error.js:79:42)
     at C:\Users\.....\Documents\Code\Shopify\Apps\.....\node_modules\@shopify\shopify-api\dist\clients\http_client\http_client.js:261:35
     at runMicrotasks (<anonymous>)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)

I tried to add the tries option like that:

await client.query({
  data: {
    query: mutationString,
    variables: {
      input: productData,
    },
    tries: 10,
  },
});

//and like that
await client.query({
  data: {
    query: mutationString,
    variables: {
      input: productData,
    },  
  },
  tries: 10,
});

The only way I managed to make it work is by doing something like that:

try{
  await client.query({
    data: {
      query: mutationString,
      variables: {
        input: productData,
      },
    },
  });
}
catch(err){
  retryRequest();
}

In the retry in the catch so far it always seems to be working. So I'd expect the tries option to do the same thing instead of having to do a catch and retry manually.

tommypepsi avatar Jun 09 '22 16:06 tommypepsi