Unexpected error: "migrate database: sqlite: step: database is locked" #96
-
Hi, thanks for the great package, it's been very useful for me. I'm using the For more context on when this error is triggered in the automated tests.
Reading the docs, the default busy option appears to be Reading through the package code I'm unsure why I'd be seeing this error either, but I'm hoping you have some idea. Is there something special with the migration startup itself that might make this error appear? For reference: my code that is establishing a pool Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I suspect the problem is with the code you've sent over. There may be transient errors before |
Beta Was this translation helpful? Give feedback.
@zombiezen I've discovered a few things, with some good news.
First, the issue appears to be fixable in
sqlitemigration
ensureAppID
function. The function opens a deferred transaction that will later be upgraded to a write transaction. At the point of upgrading to a write transaction, if the database is locked, SQLite will fail immediately withSQLITE_BUSY
[1] [2] and the busy timeout will have no effect, causing the pool to fail to start.If
ensureAppID
is switched use an immediate transaction, that tells SQLite this is a write transaction. SQLite will attempt to lock the database immediately. If a lock cannot be acquired, the busy timeout is used allowing the transaction to wait until i…