/usr/lib/cnf-update-db:sqlite3.OperationalError:/usr/lib/cnf-update-db@26:create

Bug #1875760 reported by errors.ubuntu.com bug bridge
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
command-not-found (Ubuntu)
Fix Released
Medium
Unassigned
Focal
Fix Released
Medium
Unassigned

Bug Description

[Impact]

The Ubuntu Error Tracker has been receiving reports about a problem regarding command-not-found. c-n-f- crashes when there are two parallel processes trying to update the tmpdb via its 'cnf-update-db' script. Only the first process can lock the sqlite3 database, the 2nd one will crash.

There is no impact on users, but we want to avoid the noise about those crashes in the Ubuntu Error Tracker.

This update ignores the update-db operation, if the database is already locked and logs a warning message.

[Test Case]

 * Manually lock the database
 * Run 'cnf-update-db'
 * Verify it is not crashing

sudo cp /var/lib/command-not-found/commands.db /var/lib/command-not-found/commands.db.tmp
sudo sqlite3 /var/lib/command-not-found/commands.db.tmp
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> PRAGMA locking_mode = EXCLUSIVE;
exclusive
sqlite> BEGIN EXCLUSIVE;
sqlite>

sudo rm /var/lib/command-not-found/commands.db.metadata
sudo sudo /usr/lib/cnf-update-db --verbose
echo $?

[Regression Potential]

This changes touches the 'cnf-update-db' script which creates or updates the sqlite database containing the mappings between executables and its corresponding packages. It it regresses the database might not be correctly updated anymore and thus users might not get proper package recommendations when they try to execute a non-installed application.

[Original Bug Description]

The Ubuntu Error Tracker has been receiving reports about a problem regarding command-not-found. This problem was most recently seen with package version 20.04.2, the problem page at https://errors.ubuntu.com/problem/e1fb83cff555154efc036bf0674053c5e555d96b contains more details, including versions of packages affected, stacktrace or traceback, and individual crash reports.
If you do not have access to the Ubuntu Error Tracker and are a software developer, you can request it at http://forms.canonical.com/reports/.

tags: added: rls-ff-incoming
tags: added: groovy
Changed in command-not-found (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

imho we should be resilient.

Catch errors, ignore them, report success / skip, and ensure that ux is fine.

As a reproducer, one should be able to lock the db externally, run apt-update and see how it looks like.

tags: removed: rls-ff-incoming
Changed in command-not-found (Ubuntu Focal):
status: New → Triaged
Changed in command-not-found (Ubuntu):
status: New → Triaged
Changed in command-not-found (Ubuntu Focal):
importance: Undecided → Medium
tags: added: id-5ed914750353bc78c899460b
Revision history for this message
Lukas Märdian (slyon) wrote :

This is a working reproducer:

sudo cp /var/lib/command-not-found/commands.db /var/lib/command-not-found/commands.db.tmp
sudo sqlite3 /var/lib/command-not-found/commands.db.tmp
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> PRAGMA locking_mode = EXCLUSIVE;
exclusive
sqlite> BEGIN EXCLUSIVE;
sqlite>

sudo rm /var/lib/command-not-found/commands.db.metadata
sudo PYTHONPATH=. ./cnf-update-db --verbose
Traceback (most recent call last):
  File "./cnf-update-db", line 26, in <module>
    col.create(db)
  File "/home/lukas/canonical/01-Distro/command-not-found/CommandNotFound/db/creator.py", line 92, in create
    con.executescript(create_db_sql)
sqlite3.OperationalError: database is locked

Revision history for this message
Lukas Märdian (slyon) wrote :
Revision history for this message
Lukas Märdian (slyon) wrote :
Revision history for this message
Lukas Märdian (slyon) wrote :

I've attached two debdiff patches to fix the problem for focal (command-not-found 20.04.2) and groovy (command-not-found 20.10.0). I'm looking for a sponsor/review.

Changed in command-not-found (Ubuntu):
status: Triaged → Fix Committed
Changed in command-not-found (Ubuntu Focal):
status: Triaged → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package command-not-found - 20.10.1

---------------
command-not-found (20.10.1) groovy; urgency=medium

  * Avoid crash if tmpdb is locked. Skip execution and let the other process
    do its job. (LP: #1875760)

 -- Lukas Märdian <email address hidden> Mon, 03 Aug 2020 13:06:59 +0200

Changed in command-not-found (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Lukas Märdian (slyon) wrote :

Apparently version 20.04.3 has already be used/burned in focal.
Attaching another debdiff `cnf-focal2.debdiff`, to bump the version to 20.04.4 ...

Lukas Märdian (slyon)
description: updated
Revision history for this message
Łukasz Zemczak (sil2100) wrote : Please test proposed package

Hello errors.ubuntu.com, or anyone else affected,

Accepted command-not-found into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/command-not-found/20.04.4 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in command-not-found (Ubuntu Focal):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-focal
Revision history for this message
Lukas Märdian (slyon) wrote :

Hello Lukasz,

I could successfully verify this SRU inside a Focal LXD container for command-not-found 20.04.4:
root@f:~# dpkg -l | grep command-not-found
ii command-not-found 20.04.4 all Suggest installation of packages in interactive bash sessions
ii python3-commandnotfound 20.04.4 all Python 3 bindings for command-not-found.

root@f:~# apt update
...
root@f:~# cp /var/lib/command-not-found/commands.db /var/lib/command-not-found/commands.db.tmp
root@f:~# ll /var/lib/command-not-found/
total 6064
drwxr-xr-x 2 root root 4096 Aug 27 07:11 ./
drwxr-xr-x 24 root root 4096 Aug 27 07:08 ../
-rw-r--r-- 1 root root 3096576 Aug 27 07:11 commands.db
-rw-r--r-- 1 root root 3634 Aug 27 07:11 commands.db.metadata
-rw-r--r-- 1 root root 3096576 Aug 27 07:11 commands.db.tmp
root@f:~# sqlite3 /var/lib/command-not-found/commands.db.tmp
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> PRAGMA locking_mode = EXCLUSIVE;
exclusive
sqlite> BEGIN EXCLUSIVE;
sqlite>

root@f:~# rm /var/lib/command-not-found/commands.db.metadata
root@f:~# /usr/lib/cnf-update-db --verbose
WARNING:root:/var/lib/command-not-found/commands.db.tmp is locked by another process. Ignoring.
root@f:~# echo $?
0

After the database is unlocked, the application runs as expected:
root@f:~# /usr/lib/cnf-update-db --verbose
INFO:root:processed 14855 packages in 1.45s

tags: added: verification-done-focal
removed: verification-needed-focal
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package command-not-found - 20.04.4

---------------
command-not-found (20.04.4) focal; urgency=medium

  * Avoid crash if tmpdb is locked. Skip execution and let the other process
    do its job. (LP: #1875760)

 -- Lukas Märdian <email address hidden> Mon, 03 Aug 2020 13:10:24 +0200

Changed in command-not-found (Ubuntu Focal):
status: Fix Committed → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of the Stable Release Update for command-not-found has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.