stream-chat-flutter icon indicating copy to clipboard operation
stream-chat-flutter copied to clipboard

Race condition with persist when creating a channel and deleting it right away

Open hajajmaor opened this issue 7 months ago • 0 comments

Which packages are you using?

stream_chat_flutter, stream_chat_persistance

On what platforms did you experience the issue?

iOS, Android, MacOS

What version are you using?

7.2.2

What happened?

We are developing a feature like ChatGPT channels. We create a channel and push the page. If the user doesn't send a message in the channel, we call it channel.delete(). Problem: When using the StreamChannelListView, we see the deleted channels, and then the page es, refreshes, and they are gone because of the way the StreamChannelListController works with the doInitialLoad method. Furthermore, logging this method:

  @override
  Future<void> deleteChannels(List<String> cids) {
    assert(_debugIsConnected, '');
    _logger.info('deleteChannels');
    return db!.channelDao.deleteChannelByCids(cids);
  }

deleteChannelByCids returned an integer with the number of affected rows, and the amount is 0. This means that the delete event arrives before the insert persists.

Steps to reproduce

1. Use the StreamChannelListView widget to view the channels; sort by creation time to see the channel first.
2. Create a new channel and push it to view.
3. Pop, and on dispose, delete the channel if no messages are sent to this channel.
4. Hot-reload the app and see the channel, or hot-reload while offline to fetch from persist only.
5. Not happening - pop the page earlier.

Supporting info to reproduce

No response

Relevant log output

No response

Flutter analyze output

No response

Flutter doctor output

[✓] Flutter (Channel stable, 3.13.9, on macOS 14.4.1 23E224 darwin-arm64, locale en-IL)
    • Flutter version 3.13.9 on channel stable at /Users/XXXX/fvm/versions/3.13.9
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (8 months ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/XXXX/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/XXXX/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.90.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.90.0

[✓] Connected device (4 available)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

hajajmaor avatar Jul 02 '24 14:07 hajajmaor