Database can no longer be locked after a lock whose autosave hit an external change
Have you searched for an existing issue?
- Yes, I tried searching and reviewed the pinned issues
Brief Summary
If a lock is requested while the open database has unsaved changes and the file on disk has changed, the lock's autosave refuses ("Database file has unmerged changes") and triggers a reload. DatabaseWidget::lock() then returns without clearing m_attemptingLock. From then on every lock request (Ctrl+L, lock all, the D-Bus lockAllDatabases call, locking on screen lock) returns immediately and does nothing, with no message, until KeePassXC is restarted.
With the SSH agent integration, that also means the keys stay in the agent, because the database never locks.
Steps to Reproduce
- Turn off "Automatically save after every change" (autosave on lock stays on, the default).
- Open a database and make a change, but don't save it.
- Change the file from outside (another machine through a sync tool, or
keepassxc-cli). When KeePassXC asks how to proceed with the reload, click Cancel. - Lock the database. The autosave is refused and the reload question is asked again. Click Cancel.
- Lock the database again, as many times as you like: nothing happens and nothing is shown.
A headless script that does exactly this, in a private X server, D-Bus session and ssh-agent, with a throwaway database: https://gist.github.com/underclockeddev/39d33d927bd6cf9ed87b18434e2d6320 It exits 0 when the bug reproduces and 1 when it does not.
Expected Versus Actual Behavior
Expected: a later lock either locks, or asks the reload question again, since the unsaved change is still sitting on a changed file.
Actual: every later lock is ignored until restart.
Cause
In DatabaseWidget::lock() (src/gui/DatabaseWidget.cpp, develop 9e0f57a):
m_attemptingLock = true;
...
saved = save();
if (!saved) {
// detect if a reload was triggered
...
if (reloadTriggered) {
return false; // m_attemptingLock is still true
}
}and at the top of the next call:
if (isLocked() || m_attemptingLock) {
return isLocked();
}The other early returns after m_attemptingLock = true reset it first. Adding m_attemptingLock = false; before this return false; makes the script above stop reproducing: each later lock asks the reload question again, as expected. ctest (non-GUI) still passes 46/46. A PR with that one line follows.
The investigation and script were done with Claude Code (Claude Opus 5.5) and reviewed by me before posting.
KeePassXC Debug Information
Reproduced on 2.7.12 (Arch package) and on develop 9e0f57a (2.8.0-beta1).
Source: keepassxreboot/keepassxc