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

Starting two different subscriptions at the same time throws "an operation already exists with this id" #90

Open
osaxma opened this issue Feb 10, 2021 · 7 comments

Comments

@osaxma
Copy link

osaxma commented Feb 10, 2021

Problem

In my app, I start two different subscriptions with two different queries at the start of the app (i.e., one listens for messages and one listens for notifications). Doing so for some reason throws the following error

{extensions: {path: $, code: start-failed}, message: an operation already exists with this id: "...... the id/key ...... " }

HasuraRequestError: an operation already exists with this id: "....... the id/key (same as above) ......"

A simple code to reproduce:

void main() async { 
  final url = '.....';
  final headers = {......};
  final query1 = 'subscription  messages { .......... }';
  final query2 = 'subscription  notifications { ......  }';

  final hasuraClient = HasuraConnect(url, headers: headers);

  (await hasuraClient.subscription(query1)).listen((event) {});
  (await hasuraClient.subscription(query2)).listen((event) {});
}

(In my app, I have them in separate places but they pretty much start at the same time)

a workaround:

adding some delay before one of the subscriptions makes solve the problem but it's not optimal (I found 300ms to be a good delay, anything lower will throw the error).

@evandrmb
Copy link

evandrmb commented Mar 2, 2021

I'm with the same problem. Add a delay doesn't feel like a good thing.

Maybe it is related to what was told here?

Update

I've tried adding some delay and in my case only works with 1 second which is pretty bad to wait.

@barbalex
Copy link

barbalex commented Jun 15, 2021

In my case the app listens to 20 tables. I had a query that worked perfectly. Then I converted it into a subscription and ran into the fact that a subscription can only query one root field (http://spec.graphql.org/June2018/#sec-Single-root-field). So I rebuilt into 20 separate subscriptions. And ran into this issue:

I/flutter (20244): {extensions: {path: $, code: start-failed}, message: an operation already exists with this id: c3Vic2NyaXB0aW9ucm93c1N1YnNjcmlwdGlvbnJvd3NMYXN0U2VydmVyUmV2QXR0aW1lc3RhbXB0enJvd3N3aGVyZXNlcnZlcnJldmF0Z3Ryb3dzTGFzdFNlcnZlclJldkF0aWR0YWJsZWlkcGFyZW50aWRnZW9tZXRyeWdlb21ldHJ5bmdlb21ldHJ5ZWdlb21ldHJ5c2dlb21ldHJ5d2RhdGFjbGllbnRyZXZhdGNsaWVudHJldmJ5c2VydmVycmV2YXRyZXZwYXJlbnRyZXZyZXZpc2lvbnNkZXB0aGRlbGV0ZWRjb25mbGljdHM=}

Seems like a killer for my app 😢

@barbalex
Copy link

I can reproduce this error:

  • running only one subscription works
  • starting two or more subscriptions results in an operation already exists with this id

@barbalex
Copy link

barbalex commented Jun 16, 2021

I looked at the code. And wondered if the key passed could be the issue (https://github.com/Flutterando/hasura_connect/blob/master/lib/src/presenter/hasura_connect_base.dart#L177).

But passing in own keys does not change the behaviour.

@barbalex
Copy link

barbalex commented Jun 16, 2021

I found the reason for this issue:

When creating a subscription hasura_connect checks if a connection already exists. If not, it creates it before returning the snapshot. But it returns the snapshot without awaiting the connection to be established: https://github.com/Flutterando/hasura_connect/blob/master/lib/src/presenter/hasura_connect_base.dart#L204.

I created a pull request to await the connection to be established: #99

You can use my branch in the meantime (based on v3.0.4):

  hasura_connect:
    git:
      url: https://github.com/barbalex/hasura_connect
      ref: master

@Bwolfs2
Copy link
Contributor

Bwolfs2 commented Sep 29, 2022

Im testing in v1.3.2 Hasura, and i cant get the error :C I add the test on playground.dart file in test folder @barbalex can u simulate that?

@sashker
Copy link

sashker commented Dec 11, 2023

At least, in version "4.0.0+4" I am still having this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants