-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
What happened?
I encounter an issue when attempting to instantiate a Realm object with different schemaObjects while utilizing the writeAsync() method. I've created two distinct functions to write data, each internally invoking realm.writeAsync(). Both functions initialize a Realm object by invoking its constructor with a specific configuration. Notably, each function has a different schemaObject specified in its configuration.
When these two functions are called within my code, the debugger becomes unresponsive during the initialization step of the Realm object within these functions. No exceptions are thrown, and the issue remains unresolved. However, if I precede these function calls with await, the code behaves as expected. Additionally, replacing realm.writeAsync() with realm.write() results in expected behavior.
Note: on modifying the code as described (replacing writeAsync() with write() or preceding function calls with await), it is necessary to clear the application data and uninstall the application to reproduce this issue.
Repro steps
- Create 2 different RealmModel
- Create 2 different function to utilize writeAsync() method
- call these 2 function without putting await in main code
NOTE: i have added full code snippet to reproduce this issue
Version
Flutter 3.19.3 Dart 3.3.1
What Atlas Services are you using?
Local Database only
What type of application is this?
Flutter Application
Client OS and version
Android SDK version - 33
Code snippets
//car.dart
import 'package:realm/realm.dart'; part 'car.realm.dart'; @RealmModel() class _Car { late String make; late String model; int? kilometers = 500; } }
//hotel.dart
import 'package:realm/realm.dart'; part 'hotel.realm.dart'; @RealmModel() class _Hotel { late String city; late int price; }
//main.dart
import 'package:flutter/material.dart'; import 'package:flutter_application_1/car.dart'; import 'package:flutter_application_1/hotel.dart'; import 'package:realm/realm.dart'; void main() { runApp(const MainApp()); } class MainApp extends StatelessWidget { const MainApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () { debugPrint("Hello World"); }, child: const Text("Click me"), ), ElevatedButton( onPressed: () { // add await here to get expected result writeCarData().then((value) => debugPrint("Car data written")); writeHotelData().then((value) => debugPrint("Hotel data written")); }, child: const Text("Click me")), ], ), ), ), ); } } Future<void> writeCarData() async { var config = Configuration.local([Car.schema]); var realm = Realm(config); var car = Car("Tesla", "Model Y", kilometers: 5); await realm.writeAsync(() { realm.add(car); }); } Future<void> writeHotelData() async { var config = Configuration.local([Hotel.schema]); var realm = Realm(config); var hotel = Hotel( "abc", 1000, ); await realm.writeAsync(() { realm.add(hotel); }); }
Stacktrace of the exception/crash you're getting
No response
Relevant log output
No response
- is caused by
-
RCORE-2123 Deadlock involving async transactions and realm_open
- Closed