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

SQLite3: Have to finalize statements before closing database handle #185

Merged
merged 2 commits into from
Dec 31, 2017

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Dec 31, 2017

By submitting this pull request, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your PR:

Please submit all pull requests against the development branch. Failure to do so will delay or deny your request

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?:

10


Imagine the following situation: A user queries some extensive data on the log term dashboard. This will cause the database to be locked for maybe up to 30 seconds. If FTL wants to write in this time window to the database, it is actually allowed to open and use it as PHP is explicitly requesting only read-only access to the database. We can even prepare all queries we want to add to the database in a TRANSACTION, however, at the end of the transaction, we won't be able to save them as the database is locked against any writes.

Problem: Since the statement that was supposed to write queries to the database is not yet finalized, sqlite3_close() actually fails and FTL keeps the database handle open forever (in an undefined status) as we haven't even considered that close can fail due to locked (I though closing will be just fine and unlock, but that is not guaranteed to be the case!).

Solution: We finalize all statements before calling sqlite3_close() after an error, that may or not be caused by a database lock. In addition, we now also check the return value of sqlite3_close() and print some error message in the future if closing the database failed (although we don't expect this to happen anymore).

This template was created based on the work of udemy-dl.

…lso print some error message in the future if closeing the database failed.

Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER added this to the v3.0 milestone Dec 31, 2017
@DL6ER DL6ER self-assigned this Dec 31, 2017
@DL6ER DL6ER changed the title SQLite3: Have to finalize statements SQLite3: Have to finalize statements before closing database handle Dec 31, 2017
@DL6ER DL6ER merged commit bc74514 into development Dec 31, 2017
@DL6ER DL6ER deleted the fix/database branch December 31, 2017 09:27
DL6ER added a commit that referenced this pull request Jan 6, 2018
SQLite3: Have to finalize statements before closing database handle
DL6ER added a commit that referenced this pull request Jan 6, 2018
SQLite3: Have to finalize statements before closing database handle

Signed-off-by: DL6ER <dl6er@dl6er.de>
DL6ER added a commit that referenced this pull request Jan 6, 2018
SQLite3: Have to finalize statements before closing database handle

Signed-off-by: DL6ER <dl6er@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants