Skip to content

Commit

Permalink
Set SQLite busy timeout to avoid "database is locked" when there is db
Browse files Browse the repository at this point in the history
contention.
  • Loading branch information
mmichalek committed Nov 17, 2015
1 parent 1e5fa46 commit 04b46ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions symmetric-client-clib/inc/common/ParameterConstants.h
Expand Up @@ -93,4 +93,6 @@
#define SYM_PARAMETER_HTTPS_VERIFIED_SERVERS "https.verified.server.names"
#define SYM_PARAMETER_HTTPS_ALLOW_SELF_SIGNED_CERTS "https.allow.self.signed.certs"

#define SYM_PARAMETER_SQLITE_BUSY_TIMEOUT_MS "sqlite.busy.timeout.ms"

#endif
2 changes: 2 additions & 0 deletions symmetric-client-clib/inc/db/platform/sqlite/SqlitePlatform.h
Expand Up @@ -28,6 +28,8 @@
#include "db/platform/sqlite/SqliteDdlReader.h"
#include "db/sqlite/SqliteSqlTemplate.h"

#define SYM_SQLITE_DEFAULT_BUSY_TIMEOUT_MS "30000"

typedef struct SymSqlitePlatform {
SymDatabasePlatform super;
sqlite3 *db;
Expand Down
5 changes: 5 additions & 0 deletions symmetric-client-clib/src/db/platform/sqlite/SqlitePlatform.c
Expand Up @@ -85,6 +85,11 @@ SymSqlitePlatform * SymSqlitePlatform_new(SymSqlitePlatform *this, SymProperties
sqlite3_close(this->db);
return NULL;
}

int busyTimeout = atoi(properties->get(properties, SYM_PARAMETER_SQLITE_BUSY_TIMEOUT_MS, SYM_SQLITE_DEFAULT_BUSY_TIMEOUT_MS));

sqlite3_busy_timeout(this->db, busyTimeout);

this->sqlTemplate = (SymSqlTemplate *) SymSqliteSqlTemplate_new(NULL, this->db);

SymLog_info("Detected database '%s', version '%s'", super->name, super->version);
Expand Down

0 comments on commit 04b46ad

Please sign in to comment.