Import partially failed General error: 5 database is locked

I have nextcloud instance with sqlite database.
I am trying to import an ics file with tasks, after import I have this in web-browser:

Import partially failed. Imported 82 out of 93

And in the logs:

message":"An exception occurred while executing a query: SQLSTATE[HY000]: 
General error: 5 database is locked","exception":{},"CustomMessage":"An exception occurred while executing a query:
SQLSTATE[HY000]: General error: 5 database is locked"

Full log:

{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":280,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":326,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/CalDAV/CalDavBackend.php","line":1287,"function":"executeStatement","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/public/AppFramework/Db/TTransactional.php","line":63,"function":"OCA\\DAV\\CalDAV\\{closure}","class":"OCA\\DAV\\CalDAV\\CalDavBackend","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/apps/dav/lib/CalDAV/CalDavBackend.php","line":1238,"function":"atomic","class":"OCA\\DAV\\CalDAV\\CalDavBackend","type":"->","args":[["Closure"],["OC\\DB\\ConnectionAdapter"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/CalDAV/Calendar.php","line":199,"function":"createCalendarObject","class":"OCA\\DAV\\CalDAV\\CalDavBackend","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1098,"function":"createFile","class":"Sabre\\CalDAV\\Calendar","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":504,"function":"createFile","class":"Sabre\\DAV\\Server","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPut","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:PUT",[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":373,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":172,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php","Line":130}}},"message":"An exception occurred while executing a query: SQLSTATE[HY000]: General error: 5 database is locked","exception":{},"CustomMessage":"An exception occurred while executing a query: SQLSTATE[HY000]: General error: 5 database is locked"}}

Any solutions?

Are there workarounds (maybe I can load a calendar via occ)?

Ok, I found one workaround: How to get around a problem of importing ICS? - #5 by der_andere (emulate slow 3g/2g in developer console), but this does not look like a proper solution :slight_smile:

It also seems to happen when I try to move task from one task list to another

Looks like fixing this function helped:

	protected function atomic(callable $fn, IDBConnection $db) {
		$db->beginTransaction();
		try {
			$result = $fn();
			$db->commit();
			return $result;
		} catch (Throwable $e) {
			$db->rollBack();
			throw $e;
		}
	}

Essentially I added retries with backoff policy:

protected function atomic(callable $fn, IDBConnection $db) {
    $maxRetries = 100;
    $attempts = 0;

    while (true) {
        $db->beginTransaction();
        try {
            $result = $fn();
            $db->commit();
            return $result;
        } catch (Throwable $e) {
            $db->rollBack();
            $attempts++; 
            if ($attempts >= $maxRetries) {
                throw $e;
            }
            error_log("Attempt $attempts of $maxRetries failed. Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . " retrying...");

            $sleepMs = rand(1, 1000); 
            usleep($sleepMs * 1000); 
        }
    }
}

now I can move tasks!

Also, it seems that this is expected behaviour for SQLite.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.