Aws-mobile-appsync-sdk-js: Retries for mutations

Created on 19 Mar 2019  路  11Comments  路  Source: awslabs/aws-mobile-appsync-sdk-js

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"

offline to-be-reproduced appsync-core

All 11 comments

@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

@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]

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

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 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).

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?

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

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

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

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schickling picture schickling  路  3Comments

peterservisbot picture peterservisbot  路  3Comments

asadowns picture asadowns  路  3Comments

yarax picture yarax  路  3Comments

yhenni1989 picture yhenni1989  路  3Comments