Bug 354562 - packagekit backend: muon crash on install/remove package
Summary: packagekit backend: muon crash on install/remove package
Status: RESOLVED FIXED
Alias: None
Product: muon
Classification: Applications
Component: discover (show other bugs)
Version: 5.4.2
Platform: Fedora RPMs Linux
: NOR crash
Target Milestone: ---
Assignee: Aleix Pol
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-29 14:11 UTC by Elia Devito
Modified: 2016-03-01 12:39 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.4.3


Attachments
pkmon output (12.24 KB, text/plain)
2015-10-30 13:58 UTC, Elia Devito
Details
fix patch (908 bytes, text/plain)
2015-11-04 18:49 UTC, Elia Devito
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Elia Devito 2015-10-29 14:11:24 UTC
Tested on Fedora 22 with muon 5.4.2 + fix for bug #354415

Reproducible: Always

Steps to Reproduce:
1. Open muon
2. Search for Abe
3. click 'Install' (It seems to do something, then returns to showing Abe with an 'Install' button.)
4. Click the 'Install' button again  (crash)
5. After the crash, run muon again
6. See that Abe is shown as installed
7. Click 'Remove'
8. Enter admin credential (It shows Abe with a 'Install' button)
9. Click the 'Install' button (crash)


Actual Results:  
Muon crash.

Expected Results:  
Muon Install/Remove package without crash.

https://bugzilla.redhat.com/show_bug.cgi?id=1274167
Comment 1 Rex Dieter 2015-10-29 14:54:55 UTC
fyi

Truncated backtrace:
Thread no. 1 (10 frames)
 #0 QtPrivate::RefCount::ref at /usr/include/qt5/QtCore/qrefcount.h:54
 #1 QString::QString at /usr/include/qt5/QtCore/qstring.h:878
 #2 PackageKitResource::installedPackageId at ../../../../libmuon/backends/PackageKitBackend/PackageKitResource.cpp:68
 #3 PackageKitResource::availablePackageId at ../../../../libmuon/backends/PackageKitBackend/PackageKitResource.cpp:63
 #4 PKTransaction::start at ../../../../libmuon/backends/PackageKitBackend/PKTransaction.cpp:46
 #5 ResourcesModel::qt_static_metacall at moc_ResourcesModel.cpp:157
 #6 ResourcesModel::qt_metacall at moc_ResourcesModel.cpp:264
 #7 QQmlObjectOrGadget::metacall at /usr/src/debug/qtdeclarative-opensource-src-5.5.0/src/qml/qml/qqmlpropertycache.cpp:1689
 #8 CallMethod at /usr/src/debug/qtdeclarative-opensource-src-5.5.0/src/qml/jsruntime/qv4qobjectwrapper.cpp:1160
 #9 CallPrecise at /usr/src/debug/qtdeclarative-opensource-src-5.5.0/src/qml/jsruntime/qv4qobjectwrapper.cpp:1409
Comment 2 Aleix Pol 2015-10-29 19:50:17 UTC
Could you try the following patch and tell me what's the added output?

diff --git a/libmuon/backends/PackageKitBackend/PackageKitResource.cpp b/libmuon/backends/PackageKitBackend/PackageKitResource.cpp
index f1ee811..3f51253 100644
--- a/libmuon/backends/PackageKitBackend/PackageKitResource.cpp
+++ b/libmuon/backends/PackageKitBackend/PackageKitResource.cpp
@@ -65,6 +65,7 @@ QString PackageKitResource::availablePackageId() const
 
 QString PackageKitResource::installedPackageId() const
 {
+    qDebug() << "installed" << m_packages;
     return m_packages[PackageKit::Transaction::InfoInstalled].first();
 }
Comment 3 Elia Devito 2015-10-29 20:48:03 UTC
First crash: (after Abe install):
  Remove transaction: "abe" with 1 transactions running
  installed QMap()

Second crash: (after Abe remove):
  installed QMap((1, ("abe;1.1-25.fc22;x86_64;installed:fedora")))
  Remove transaction: "abe" with 1 transactions running
  installed QMap()
Comment 4 Elia Devito 2015-10-29 23:49:08 UTC
To clarify: https://www.youtube.com/watch?v=6qa7sZ6t8Uo
Comment 5 Rex Dieter 2015-10-30 12:28:32 UTC
I suspect one complication here may be no (or stale) packageKit metadata cache (may explain why I cannot reproduce the problems seen here personally).

May be worth :
* try running 'pkmon' while performing this test, to see what packagekitd is doing
* prior to testing muon, run: pkcon refresh force
Comment 6 Elia Devito 2015-10-30 13:58:41 UTC
Created attachment 95225 [details]
pkmon output
Comment 7 Elia Devito 2015-10-30 19:42:23 UTC
the problem seem be caused by PKTransaction::cleanup() 
exactly this rows:

PackageKit::Transaction* t = PackageKit::Daemon::resolve(resource()->packageName(), PackageKit::Transaction::FilterArch | PackageKit::Transaction::FilterLast);
qobject_cast<PackageKitResource*>(resource())->resetPackageIds();
connect(t, SIGNAL(package(PackageKit::Transaction::Info,QString,QString)), resource(), SLOT(addPackageId(PackageKit::Transaction::Info, QString,QString)));

the "package" signal isn't emitted and the m_packages map remain empty

The question is why?
Comment 8 Aleix Pol 2015-11-03 16:00:32 UTC
Git commit a24e495c2eea95e76b1389bdffaf27e30d7e273a by Aleix Pol.
Committed on 03/11/2015 at 15:54.
Pushed by apol into branch 'Plasma/5.4'.

Batch resource package id's

This way we make sure it stays consistent

M  +12   -4    libmuon/backends/PackageKitBackend/PKTransaction.cpp
M  +3    -2    libmuon/backends/PackageKitBackend/PackageKitResource.cpp
M  +3    -1    libmuon/backends/PackageKitBackend/PackageKitResource.h

http://commits.kde.org/muon/a24e495c2eea95e76b1389bdffaf27e30d7e273a
Comment 9 Elia Devito 2015-11-03 18:05:43 UTC
last commit don't fix this, the package signal isn't emitted and the setPackages() pass a empty QMap to PackageKitResource, consequently muon crash

if you apply this path:
--- a/libmuon/backends/PackageKitBackend/PKTransaction.cpp	2015-11-03 18:17:55.094175121 +0100
+++ b/libmuon/backends/PackageKitBackend/PKTransaction.cpp	2015-11-03 18:55:18.620076119 +0100
@@ -103,13 +103,18 @@
         m_trans = nullptr;
     }
     PackageKit::Transaction* t = PackageKit::Daemon::resolve(resource()->packageName(), PackageKit::Transaction::FilterArch | PackageKit::Transaction::FilterLast);
+    
+    connect(t, SIGNAL(errorCode(PackageKit::Transaction::Error,QString)), this, SLOT(errorFound(PackageKit::Transaction::Error,QString)));
+    
     connect(t, &PackageKit::Transaction::package, t, [t](PackageKit::Transaction::Info info, const QString& packageId) {
+        qDebug() << "package signal emitted";
         QMap<PackageKit::Transaction::Info, QStringList> packages = t->property("packages").value<QMap<PackageKit::Transaction::Info, QStringList>>();
         packages[info].append(packageId);
         t->setProperty("packages", qVariantFromValue(packages));
     });
 
     connect(t, &PackageKit::Transaction::finished, t, [t, this](PackageKit::Transaction::Exit status, uint runtime){
+        qDebug() << "finished signal emitted";
         QMap<PackageKit::Transaction::Info, QStringList> packages = t->property("packages").value<QMap<PackageKit::Transaction::Info, QStringList>>();
         qobject_cast<PackageKitResource*>(resource())->setPackages(packages);
         setStatus(Transaction::DoneStatus);

in output I receive only "finished signal emitted" and no error message
Comment 10 Aleix Pol 2015-11-04 16:41:00 UTC
Can you confirm that `pkcon resolve <package>` where package is the package you're trying to un/install returns something?
Comment 11 Elia Devito 2015-11-04 18:16:18 UTC
yes, it return the package info:
      
Installato      abe-1.1-25.fc22.x86_64 (installed:fedora)                       Scrolling, platform-jumping, ancient pyramid exploring game
Comment 12 Elia Devito 2015-11-04 18:49:42 UTC
Created attachment 95313 [details]
fix patch

This patch fix problem but I'm not sure this is a correct solution
Comment 13 Aleix Pol 2015-11-05 15:52:54 UTC
Git commit 456c5a03b5397f58a4915c40eca3e5ca7225f794 by Aleix Pol.
Committed on 05/11/2015 at 15:47.
Pushed by apol into branch 'Plasma/5.4'.

Fix package resolution after un/installing

Thanks a lot to Elia Devito for the patch!

M  +1    -1    libmuon/backends/PackageKitBackend/PKTransaction.cpp

http://commits.kde.org/muon/456c5a03b5397f58a4915c40eca3e5ca7225f794
Comment 14 Jeanne Varasco 2016-03-01 12:39:54 UTC
I have the same problem when I try to install plasma-widget-cwp widget (it doesn't appear in installed softwares) and in "add widget".
I also have the same problem hen I try to install weather-widget a part of necessary packages were not installed.