aws-mobile-appsync-sdk-js icon indicating copy to clipboard operation
aws-mobile-appsync-sdk-js copied to clipboard

Retries for mutations

Open nealyip opened this issue 6 years ago • 13 comments

The appsync js sdk keeps retrying for mutations even if 401 has been thrown.

retries

Here is a snippet of my code

const args: AWSAppSyncClientOptions = {
            url: this.configService.config.graphqlEndpoint,
            region: this.configService.config.region,
            auth: {
                type: this.configService.config.authenticationType,
                jwtToken: async () => await this.authorize()
            }
        };
this.client = new AWSAppSyncClient(args);
this.client.hydrated().then(async (client: AWSAppSyncClient<any>) => {
      const result = await client.mutate(options);
      console.log(result);
});

How can I make no retries for 401 error?

Thanks

Dependencies "aws-appsync": "~1.7.2"

nealyip avatar Mar 19 '19 04:03 nealyip

@nealyip what's the actual version you have in your project? It might be different if you have a yarn.lock or packgae-lock.json

e.g.

yarn list | grep appsync
# or
npm list --pattern appsync

manueliglesias avatar Mar 20 '19 21:03 manueliglesias

@nealyip what's the actual version you have in your project? It might be different if you have a yarn.lock or packgae-lock.json

e.g.

yarn list | grep appsync
# or
npm list --pattern appsync

Thanks for your reply.

Here attached the result

npm list --pattern aws-appsync `-- [email protected]

nealyip avatar Mar 22 '19 03:03 nealyip

Same problem here with [email protected] (not posting the code as it's similar to @nealyip's)

fabrizioromanelli avatar May 17 '19 10:05 fabrizioromanelli

This is interesting, I thought it was fixed in #308

Do you see the same behavior if you do disableOffline: true:

const args: AWSAppSyncClientOptions = {
            url: this.configService.config.graphqlEndpoint,
            region: this.configService.config.region,
            auth: {
                type: this.configService.config.authenticationType,
                jwtToken: async () => await this.authorize()
            },
           disableOffline: true
        };
this.client = new AWSAppSyncClient(args);

manueliglesias avatar May 17 '19 19:05 manueliglesias

@manueliglesias I've just tried with disableOffline: true and it is working like a charm. First the time the error has been thrown, AppSync client stops trying for mutation (or query).

fabrizioromanelli avatar May 18 '19 07:05 fabrizioromanelli

Getting the same issue when the AppSync URL doesn't exist (i.e. domain not found). The mutation just keeps retrying infinitely. Is there a way to configure the number of retries?

fsproru avatar Mar 12 '20 01:03 fsproru

Same issue when jwtToken expired. The mutation just keeps retrying infinitely.

leehung-net avatar Apr 24 '20 07:04 leehung-net

Hey @manueliglesias, hope all is well. Just following up here. The issue still exists in version 1.8.1 and 1.8.0. disableOffline: true also doesn't change the behavior. AppSync client keeps on retrying on an error coming from the server (in our case 504).

It would be fantastic if we can disable this retrying behavior so our app can be resilient to network errors.

Let us know if there is any way we can make it happen.

Thank you, Alex

fsproru avatar Jul 05 '20 22:07 fsproru

The issue still exists in 3.0.3 and even in 4.0.0. disableOffline has absolutely no effect.

dennis3001 avatar Aug 17 '20 10:08 dennis3001

As @fsproru said, it would be great if we can disable this retrying behavior. This really needs to be addressed and fixed. Our company uses this library for AppSync (GraphQL) requests and we may be forced to find an alternative solution.

An easy way to reproduce this issue is by opening browser dev tools and changing network mode to "offline" (to cause query to fail), and then invoking a query with this library. It appears that this library handles the network error itself without propagating it up for us to handle.

Joroze avatar Sep 30 '20 13:09 Joroze

It's already been a long time since I reported this problem. I solved this by switching to aws-amplify long time ago.

However, I keep seeing people encountering similar issues. That's why I made this repo hopefully helpful to the developers of this appsync sdk to address the issue more easily. I'm not sure if this's the exact cause of the issue that others here are encountering.

https://github.com/nealyip/nealyip-sample-appsync-infinite-retries

As a quick starter

npm i
npm run start

For query operations,

Screenshot 2020-10-13 222000

if a mock server returned 400, 401, 403, 404 etc, it would stop at the first response. However, if it returned 500, 502, 503 etc, it would loop infinitely.

For mutation operations,

The above which happens on 5xx errors happens on 4xx too

Screenshot 2020-10-13 222141

The infinite retries mean we can't leave the loop and recover the error manually.


    theClient.hydrated().then(async (client: AWSAppSyncClient<any>) => {
      if (mode === 'query') {
        return client.query({
          query: randomQuery
        });
      }
      return client.mutate({
        mutation: randomMutation
      });
    }).then(r => this.loading = false).catch(err => {
      console.error('Caught', err.message);
      this.loading = false;
      // Do sth to recover the error
      this.errorMessage = err.message;
    });

What we expect is to get to the catch block and process custom error handling rather than letting our users wait infinitely without a proper way to notify them of an error.

nealyip avatar Oct 13 '20 14:10 nealyip

Hi any updates on this? still replicating the issue in 4.1.6 thanks

Xiralv avatar May 30 '22 04:05 Xiralv

Seems to still be an issue in 4.1.8

jzybert avatar Nov 08 '22 21:11 jzybert