Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions seem to have a caching issue #510

Open
philiiiiiipp opened this issue Jan 20, 2020 · 2 comments
Open

Subscriptions seem to have a caching issue #510

philiiiiiipp opened this issue Jan 20, 2020 · 2 comments
Assignees
Labels
subscription-link Related to AppSync Subscription Link issues to-be-reproduced We need to reproduce this issue

Comments

@philiiiiiipp
Copy link

Do you want to request a feature or report a bug?

bug

What is the current behavior?

We subscribe to a query using the subscribeToMore function of apollo.

We then use the updateQuery: (previousResult, ...args) => { ... } function to update the query when new subscription data comes in.

Our items always have an id and a version { id: string, _v: number, ... }. Merging is done by going through the query items and update the entry with the fitting id if the entry coming from the subscription has a higher version or inserting if the entry does not exist yet.

What we noticed is that if we are getting subscriptions e.g.

{ id: '1', _v: 4, name: 'Peter' }
{ id: '1', _v: 5, name: 'Bob' }

where the version is in correct order, everything is fine. If we get

{ id: '1', _v: 5, name: 'Bob' }
( waiting for some seconds )
{ id: '1', _v: 4, name: 'Peter' }

ordering incorrect, but with some time difference everything is fine too, Bob is displayed.

But, if we are getting subscriptions in rappid succession in wrong ordering

{ id: '1', _v: 5, name: 'Peter' }
{ id: '1', _v: 4, name: 'Bob' }

Bob is displayed. When debugging the updateQuery: (previousResult, ...args) => { function we saw that even though { id: '1', _v: 4, name: 'Bob' } is just coming in, it seems to already be part of the previousResult entry. Which is weird as it just came back from the subscription.

Is there a possibility that there is some caching going on inside the AwsAppsync subscription client ? Or are those subscription updates handled asyncronously ?

The reason why we are coming to this conclusion is that if we change the dataId to include the version, this issue dissappears:

dataIdFromObject: obj => {
  const { id, __typename, _v = '0' } = obj;

  if (id == null) return defaultDataIdFromObject(obj);

  return `${__typename}:${id}:${_v}`;
},

What is the expected behavior?

Subscriptions coming in in rappid succession should be handled in syncronously.

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?

We were able to reproduce this in Chrome and Firefox

@Ashish-Nanda Ashish-Nanda added the investigating Amplify is looking into the issue label Jan 22, 2020
@elorzafe
Copy link
Contributor

@philiiiiiipp can you validate your update function to replace the value only if the version is greater than existing one?

@philiiiiiipp
Copy link
Author

Yes, it does exactly that. It also works fine as long as we are not getting the items in rappid succession ( including if they are coming in different order ).

@sammartinez sammartinez removed the investigating Amplify is looking into the issue label Mar 31, 2020
@elorzafe elorzafe added to-be-reproduced We need to reproduce this issue subscription-link Related to AppSync Subscription Link issues labels Apr 15, 2020
@elorzafe elorzafe added this to the Subscription link bug fixes milestone Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subscription-link Related to AppSync Subscription Link issues to-be-reproduced We need to reproduce this issue
Projects
None yet
Development

No branches or pull requests

4 participants