-
Notifications
You must be signed in to change notification settings - Fork 38
fix: Properly close stmt and conn when using idb #232
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
Conversation
Deleting the statement object doesn't free the underlying resources, causing memory leaks. Instead, we need to close both the connection and the statement to free these resources. We can let the runtime delete the objects as well. Fixes #230
This might not be 100% correct for sync mode, since I don't know how errors are returned in that case (exceptions?) |
Yup prepareSync would throw an error here. This won't give you the chance to properly close things out with Looks we can get around this by passing a callback to prepareSync. That way we can check for an error just like the async case |
I've changed the whole design. Since everything throws errors, wrap the whole thing in try/finally blocks. This way we don't eve need the function, since the clean up code only happens in one place. The only downfall with this design is that cleanup will not be done until after the user's callback chain has returned to us. |
I tried running through the tests with:
I'm trying to figure out why. |
The JavaScript See https://nodejs.org/api/errors.html#errors_error_first_callbacks Running the command test with verbose mode on we can see:
Looks like the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we avoid try..catch
mechanism when in async
mode.
Ugh, that makes sense. The fact that the whole thing is wrapped in an exception handler and the code throws is what lead me to that. Now I wonder if the code is currently broken. |
I moved the try/finally around the sync mode block and in the async block I used the same way I had before. |
Throwing an error withing the async callback is definitely wrong. Furthermore Having error first callbacks in |
Those changes fixed the issue. |
Yeah, I think that's all it's doing in this case: the exception is thrown and then caught and printed out. The exception shouldn't get back to the user - if they use async mode, they either they didn't get an error and the callback is called or they did and the callback is not. This is bonkers, but I don't know how to fix it without changing behavior, which is why we did what we did in v1.0. My goal wasn't to change that, but to fix the problem at hand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@abmusse can you please make a v0.1.7 release? |
I believe you meant After making the release on github also publish on npm? |
Yep. Caught my mistake a hair too late. |
Deleting the statement object doesn't free the underlying resources,
causing memory leaks. Instead, we need to close both the connection and
the statement to free these resources. We can let the runtime delete the
objects as well.
Fixes #230