-
Notifications
You must be signed in to change notification settings - Fork 203
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
Use sqlite3_close_v2 to close databases. #557
Conversation
Close databases in a deferred manner if there are unclosed prepared statements. Previously closing a database while statements were open resulted in a `BusyException`. See https://www.sqlite.org/c3ref/close.html for more context.
I know I'm late to the party (again, really sorry), but do we actually want to do this? If someone closes a database while they have statements open, that is a bug, so I'd expect an exception. We definitely need the "close without exception" behavior for fork safety, but could we just introduce a "force close" or something? Maybe like |
@tenderlove Been thinking about this. I think what you're saying is: maybe people will be silently leaking db connections because they're not being reminded to clean up their statements by a failing I guess I get it, and I acknowledge it's a change in behavior from previous versions. But also how is this any different than anything else in Ruby? It was only a bug before because GC didn't always clean up databases and statements; now this is handled well. Is there a specific use case you're worried about leaking in non-obvious ways? |
Just to close the loop on this (since we discussed it privately already):
I'm not worried that people will be silently leaking database connections. I'm worried that people will mistakenly leave statements in an "unfinished" state. Previously, users would have to specifically close their statements before they could close the database, effectively forcing them to say "I'm done with this statement now" (even if the statement had more rows to read, etc) before being allowed to close the db. After this patch, there's no feedback to users that they've not completed using a statement.
Yep, totally agree with this. I think it's what we agreed upon privately, and I just want to make sure we document it publicly. 😄
I was thinking we could do both: have good GC cleanup and raise an exception if there are "dangling" statements. I think the behavior we have in |
Close databases in a deferred manner if there are unclosed prepared statements. Previously closing a database while statements were open resulted in a
BusyException
.See https://www.sqlite.org/c3ref/close.html for more context.