Skip to content

Make sure cursors are closed everywhere / Database is locked #10566

Closed

Description

@PVince81

This follows my discovery here: #7539 (comment)

In some cases when prepared statements are used, if the cursors aren't closed explicitly, there is a higher risk to run into "Database is locked" issues on SQLite (and maybe max cursors reached on Oracle). We cannot rely on garbage collection to free these resources.

We should go through the core code and find the prepared statements that aren't closed explicitly.
The most likely to cause trouble is ones that might be called repeatedly or the ones defined as class attributes instead of local variables.

What do you think ?

@karlitschek @bantu @icewind1991 @DeepDiver1975 @th3fallen @butonic

Activity

  1. butonic commented on Aug 21, 2014

    @butonic
    Contributor

    a hint: http://php.net/manual/de/pdo.query.php

    If you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call may fail. Call PDOStatement::closeCursor() to release the database resources associated with the PDOStatement object before issuing your next call to PDO::query().

  2. butonic commented on Aug 21, 2014

    @butonic
    Contributor

    and from http://www.sqlite.org/opcode.html#OpenRead

    There will be a read lock on the database whenever there is an open cursor. If the database was unlocked prior to this instruction then a read lock is acquired as part of this instruction. A read lock allows other processes to read the database but prohibits any other process from modifying the database. The read lock is released when all cursors are closed. If this instruction attempts to get a read lock but fails, the script terminates with an SQLITE_BUSY error code.

    So, when a SELECT query is executed, but the result set is still open when a modifying SQL statement is executed on the same table we will get the DATABASE LOCKED error.

  3. PVince81 commented on Aug 21, 2014

    @PVince81
    ContributorAuthor

    Side-note: I'm now struggling with Oracle problems now after adding closeCursor() instructions in my code. Will report later when I found a solution...

  4. butonic commented on Aug 21, 2014

    @butonic
    Contributor

    Now this seems interesting end exactly the kind of crappy hacking needed to get oracle working http://php.net/manual/de/function.oci-free-statement.php#81577 Now investigating if doctrine does free the cursor AND the statement.

  5. PVince81 commented on Aug 21, 2014

    @PVince81
    ContributorAuthor

    Not sure, but on my test machine I had to increase the number of cursors because I was getting "Max cursors reached" when running all unit tests on Oracle.

    The issue I'm having now is different, see #7539 (comment)
    I hope to be able to fix it without having to remove the explicit "closeCursor()".

  6. added this to the milestone on Sep 5, 2014
  7. PVince81 commented on Sep 9, 2014

    @PVince81
    ContributorAuthor

    I don't think we want to risk introducing regressions in OC 7 by adding cursor closing everywhere ?
    Should be fine for OC 8

  8. modified the milestones: , 2014-sprint-03 on Sep 15, 2014
  9. 46 remaining items

  10. modified the milestones: , on Apr 4, 2015
  11. DeepDiver1975 commented on Oct 6, 2015

    @DeepDiver1975
    Contributor

    @karlitschek @cmonteroluque

    To late in the dev cycle - I suggest to postpone this to 9.0 or even backlog - THX

  12. modified the milestones: backlog, on Oct 6, 2015
  13. karlitschek commented on Oct 6, 2015

    @karlitschek
    Contributor

    yes. too late for proper testing anyways

  14. ownclouders commented on Jan 13, 2018

    @ownclouders
    Contributor

    Hey, this issue has been closed because the label status/STALE is set and there were no updates for 7 days. Feel free to reopen this issue if you deem it appropriate.

    (This is an automated comment from GitMate.io.)

  15. PVince81 commented on Jan 15, 2018

    @PVince81
    ContributorAuthor

    Haven't heard of such issues any more, leaving closed.

  16. lock commented on Jul 31, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  17. locked as resolved and limited conversation to collaborators on Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions