Description
👟 Reproduction steps
Create a Flutter project and integrate the Appwrite SDK.
Set up real-time subscriptions using RealtimeMixin.subscribeTo.
The error occurs intermittently, particularly when subscriptions are being closed or created while the _createSocket method is running.
E/flutter (22154): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Concurrent modification during iteration: _Map len:0.
E/flutter (22154): #0 _CompactIterator.moveNext (dart:collection-patch/compact_hash.dart:714:7)
E/flutter (22154): #1 RealtimeMixin._createSocket.<anonymous closure> (package:appwrite/src/realtime_mixin.dart:91:49)
E/flutter (22154): #2 _RootZone.runGuarded (dart:async/zone.dart:1582:10)
E/flutter (22154): #3 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:418:13)
E/flutter (22154): #4 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:428:7)
E/flutter (22154): #5 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:317:7)
E/flutter (22154): #6 _ForwardingStream._handleDone (dart:async/stream_pipe.dart:99:10)
👍 Expected behavior
I'm encountering a "Concurrent modification during iteration: _Map len:0" error when using the Appwrite Flutter SDK for real-time subscriptions. This error seems to be originating within the RealtimeMixin._createSocket method (line 91).
The error appears to be related to concurrent access to the _subscriptions map within the RealtimeMixin.
This issue causes the app to crash unexpectedly, disrupting the real-time functionality.
👎 Actual Behavior
The app crashes: The "Unhandled Exception: Concurrent modification during iteration" is a critical error. In most cases, this would lead to an immediate crash of the Flutter application.
Disrupted real-time updates: The error originates from the RealtimeMixin, which is responsible for managing real-time data updates. So, even before the potential crash, the functionality related to receiving and handling real-time events would likely be disrupted.
Difficulty pinpointing the issue: The stack trace points to the Appwrite SDK's internal code. This makes it challenging for developers to directly diagnose and fix the issue, as it might require modifications to the SDK itself.
🎲 Appwrite version
Version 1.0.x
💻 Operating system
MacOS
🧱 Your Environment
- Self-hosted Appwrite: I'm using Appwrite self-hosted on an Azure virtual machine Azure Spot (Standard D2s v3 with 2 vCPUs and 8 GB memory, running Ubuntu 22.04).
- Appwrite Version: The Appwrite server version I'm running is appwrite/appwrite:1.5.5.
- Cloudflare Access: I access my Appwrite instance through Cloudflare by pointing my custom domain to it.
- Flutter App Configuration: My Flutter app is configured to use Appwrite in self-signed certificate mode.
👀 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?
- I have read the Code of Conduct