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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug Report: Event is triggered multiple times when subscribing to multiple (different) channels #55

Open
2 tasks done
Re-Shard opened this issue Mar 28, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@Re-Shard
Copy link

Re-Shard commented Mar 28, 2022

馃憻 Reproduction steps

Create, Update & Delete events are being triggered multiple times when subscribed to multiple channels.
In the example below there are 2 create events when a userimage is added.

First subscription:

subscribe() {
    if (userimagesSubscription == null) {
      userimagesSubscription = AppwriteApi.instance.realtime
          .subscribe(['collections.userimages.documents']);
      userimagesSubscription!.stream.listen((data) async {
        if (data.payload.isNotEmpty) {
          // Do some handling..
        }
      });
    }
  }

Second subscription:

subscribe() {
    if (interestSubscription == null) {
      interestSubscription = AppwriteApi.instance.realtime
          .subscribe(['collections.interest.documents']);
      if (interestSubscription != null) {
        interestSubscription!.stream.listen((data) async {
          if (data.payload.isNotEmpty) {
           // Do some handling..
          }
        });
      }
    }
  }

馃憤 Expected behavior

There should be only 1 trigger event per event.

馃憥 Actual Behavior

The debug console shows the following:

I/flutter ( 5914): subscription: wss://db.DOMAIN.nl/v1/realtime?project=6234aad9d50bf302d1b5&channels%5B%5D=collections.userimages.documents

I/flutter ( 5914): subscription: wss://db.DOMAIN.nl/v1/realtime?project=6234aad9d50bf302d1b5&channels%5B%5D=collections.userimages.documents&channels%5B%5D=collections.interest.documents

馃幉 Appwrite version

Version 4.0.x

馃捇 Operating system

Linux

馃П Your Environment

No response

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@Re-Shard Re-Shard added the bug Something isn't working label Mar 28, 2022
@lohanidamodar
Copy link
Member

Did you app hot-reload? That might cause the issue, hot-reload can create unexpected behavior with the websockets even when there is only one subscription. Can you try with complete hot restart and check if you still have the issue?

@Re-Shard
Copy link
Author

Did you app hot-reload? That might cause the issue, hot-reload can create unexpected behavior with the websockets even when there is only one subscription. Can you try with complete hot restart and check if you still have the issue?

@lohanidamodar it has still the same problem. It looks like it doesnt close the previous subscription, when added a new channel to the subcription.

@lohanidamodar
Copy link
Member

@Invisibleshroud ok, will test and let you know what I find.

@lohanidamodar
Copy link
Member

@Invisibleshroud hey, this only happens to me when I have either hot reloaded or hot restarted. In both cases the subscription is not closed so each time I hot restart or hot-reload, new subscription is added on top of that, so I get multiple events.
When I run the project without hot reload or hot restart, I don't have this issue. Can you confirm it's the same with you.

@lohanidamodar lohanidamodar added enhancement New feature or request and removed enhancement New feature or request labels Apr 27, 2022
@lohanidamodar
Copy link
Member

@Invisibleshroud This seems to be a issue with the Flutter web itself on hot restart this happens on normal web-socket connection as well. This is not solvable at the moment, check this issue and comments there.
flutter/flutter#69949 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants