-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Calling .close() closes all existing DB Connections? #146
Comments
No, this is a bug, it's unlikely you need two connections to the same db in your JS but I will take care of it anyways |
Allowing multiple clean connections to the DB would require far more refactoring than I have time for. I have now disabled it. If you try to open a new connection to the same DB in JS it will throw an exception. It will be released with the next major version. |
Hi @ospfranco, I understand what you meant. But the main reason I asked for this is because I have multiple backend jobs running at the same time. Example: The problem is that occasionally, when both task run at the same time, one of the scheduler will closes the other scheduler's connection when it completes it task by calling .close, and this will cause the other scheduler that has yet to complete its task to have it's DB connection closed due to calling .close will close every single opened DB connection. My example posted there is just to have a simple test case to replicate the issue that I am currently facing right now. My use case is far more complicated than the example I posted here. |
You don't need multiple connections for this. Just use |
On the new version that will be released soon, you just need |
Yes @ospfranco, initially I do not close db connection and reuse same db connection, it is working fine. But this will cause memory leak, where each query will consume the memory and does not release it if I do not call .close() and eventually it will crash the app when the memory is too low. |
You can do a simple test where you open a db connection and use a while(true) loop that constantly query something(anything simple is applicable) using the same db connection without .close(), the memory never get released until we kill the app. |
Interesting, the new version should help maybe. Objects returned by the normal |
Alright @ospfranco I will test it out and let you know again, thanks. |
8.0.1 is out, give that one a try |
Just had a quick test on 8.0.0-beta0, seems to be working very fine with no leaks at all. Will try with 8.0.1 again later. Thanks for the quick response. |
@ospfranco I'm facing |
Don't close the connection, just create one per app start |
so I just need to open the connection when app starts right? |
Read the docs, you also need to await the execute call |
I added |
Your app initialization code is wrong. When your app starts/hot reload is trying to create the DB connection again, which is wrong. I cannot tell you what's wrong because I don't have access to your code. Just create the connection once. Don't put it in a function just in a db.ts file create it at the module level: // db.ts
export const db = open({...}) Read the docs carefully. |
I got it, I put |
Describe the bug
db2 will throw 'Error: Exception in HostFunction: [OP-SQLite] DB is not open' exception even thou I closes only the first connection.
Versions:
The text was updated successfully, but these errors were encountered: