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

Could not begin read transaction (another read transaction is still active on this thread) #368

Closed
rizkyagungramadhan opened this issue Jan 11, 2022 · 6 comments
Milestone

Comments

@rizkyagungramadhan
Copy link

rizkyagungramadhan commented Jan 11, 2022

image

Hello thanks a lot for making my life easier with ObjectBox.
I faced a problem when I implemented ObjectBox using WorkManager in Flutter.

In the process there are transactions in the form of reads and writes to the database, when the read -> download from Api -> insert process has been completed I get an error "Could not begin read transaction (another read transaction is still active on this thread)" when I retry to read database in the application (the process of inserting into the database all successful).

But when the process in Work Manager is still running, everything works normally for me when I want to access the database directly in the application.

The error only appears when all work manager process has been completed.

This is my stacktrace :

E/Box     ( 9986): Storage error (code -30783)
[GETX] Info: AttendanceController Instance of 'AttendanceController' #0      ObjectBoxNativeError.throwMapped (package:objectbox/src/native/bindings/helpers.dart:78:9)
objectbox/objectbox-java#1      throwLatestNativeError (package:objectbox/src/native/bindings/helpers.dart:50:48)
objectbox/objectbox-java#2      checkObxPtr (package:objectbox/src/native/bindings/helpers.dart:32:5)
objectbox/objectbox-java#3      new Transaction (package:objectbox/src/native/transaction.dart:33:5)
objectbox/objectbox-java#4      Store._runInTransaction (package:objectbox/src/native/store.dart:299:32)
objectbox/objectbox-java#5      Store.runInTransaction (package:objectbox/src/native/store.dart:292:12)
objectbox/objectbox-java#6      BaseDao._executeQuery (package:app/entity/base_dao.dart:11:86)
objectbox/objectbox-java#7      BaseDao.findAllWhere (package:app/entity/base_dao.dart:39:74)

I am using
objectbox: ^1.3.0
Thank you, very happy if anyone can help me with this problem

@greenrobot-team greenrobot-team transferred this issue from objectbox/objectbox-java Jan 12, 2022
@greenrobot-team
Copy link
Member

Moved to objectbox-dart repo as this is using Flutter.

The underlying issue is that the transaction was not completed because it failed with a crash: "E/Box ( 9986): Storage error (code -30783)". This error is described as MDB_BAD_RSLOT "Invalid reuse of reader locktable slot". @greenrobot Do you have an idea?

How does your WorkManager code look like? Does it maybe close the database when it finished all work?

@greenrobot
Copy link
Member

@rizkyagungramadhan Are you using multiple isolates?

@rizkyagungramadhan
Copy link
Author

Moved to objectbox-dart repo as this is using Flutter.

The underlying issue is that the transaction was not completed because it failed with a crash: "E/Box ( 9986): Storage error (code -30783)". This error is described as MDB_BAD_RSLOT "Invalid reuse of reader locktable slot". @greenrobot Do you have an idea?

How does your WorkManager code look like? Does it maybe close the database when it finished all work?

No, Im not closing the database either the WorkManager result error or success.
Currently I'm handling with openStore() right after WorkManager process is done.
At least it is working now. But is it should be fine to accessing database from multiple isolates since Im using same reference to the Store object in all isolates?

@gcostaapps
Copy link

I am having the same error when trying to open my flutter project with another flutter engine. The reads of object box (on this other flutter engine) throws this error.

@greenrobot-team
Copy link
Member

@gcostaapps Thanks, but what do you mean by "open my flutter project with another flutter engine"? Can you share more details about the project?

@greenrobot-team
Copy link
Member

But is it should be fine to accessing database from multiple isolates since Im using same reference to the Store object in all isolates?

New releases have added a Store.attach API for this purpose. There are now also Store.runInTransactionAsync and Store.runAsync for running database operations using simple callback style.

Closing this then. Feel free to comment or create a new issue if this is not resolved.

@greenrobot-team greenrobot-team added this to the 1.4.0 milestone May 24, 2022
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

4 participants