Unable to initialize statically the Database or causes deadlock #105
Replies: 4 comments
-
I really like the extensive features and I hope to find a solution to make it work. Great project. |
Beta Was this translation helpful? Give feedback.
-
@milen-denev Can you test by creating the database during your server initialization instead of in lazy static? You will find an example here: src-tauri/src/main.rs#L79-L100 |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the suggestion sadly (and that's why I included the example) I cannot do that. There are use cases (this type of middleware or background services) which doesn't allow to pass a reference neither a Arc.clone() or any other type (as of my knowledge). I did a stress test in main (which may not exaclty cover my use case) and I think there something wrong with the DatabaseBuilder's lazy initialization and the Database's lazy initialization. If you combine this 2 lazy inits something goes wrong and it deadlocks (or the latency skyrockets to unimaginable levels). I don't know how the one correlates to the other, but with certainty I can say that the one is attached to the other. |
Beta Was this translation helpful? Give feedback.
-
@milen-denev You don't need to use You can move the database into the App Data ...
let db = DATABASE_BUILDER
.create_in_memory()
.expect("failed to create database");
let data = web::Data::new(db);
App::new()
.app_data(data)
.wrap_fn(|req, srv| {
let db = req.app_data::<web::Data<Database>>().unwrap();
... I used the |
Beta Was this translation helpful? Give feedback.
-
This is my code:
If I try to access this from an actix middleware, and I do requests that point to different database entries at the same time I am deadlocking the application (by application I mean every thread, or at least that's how it feels). I cannot create an instance from main() and pass it arround because simply that's impossible in my use case.
I tried putting DatabaseBuilder inside the NativeDb struct or withing the same Lazy but that's also impossible due to the way the DatabaseBuilder is made.
This is the middleware:
Beta Was this translation helpful? Give feedback.
All reactions