Bug 396527 - MTP kioslave can't be used from two different processes.
Summary: MTP kioslave can't be used from two different processes.
Status: RESOLVED FIXED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: MTP (show other bugs)
Version: 18.04.3
Platform: Archlinux Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
: 325629 331682 336399 350384 356084 359112 363593 375840 379680 383317 383628 396271 398989 401235 403198 404087 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-07-15 09:15 UTC by Mike Krutov
Modified: 2019-02-22 14:29 UTC (History)
18 users (show)

See Also:
Latest Commit:
Version Fixed In: 18.11.80


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Krutov 2018-07-15 09:15:38 UTC
Steps to reproduce:

1) Connect android phone, while having Amarok opened

2) Try to mount MTP "Android" device in Dolphin

3) See "MTP died unexpectedly"

Reproducibility: 100%. Moment Amarok is closed, Dolphine works flawlessly.
Comment 1 Jaime Torres 2018-07-15 09:50:36 UTC
Confirmed with Amarok MTP plugin enabled.
As a workaround, disabling Amarok MTP plugin makes dolphing MTP work again.

Unfortunately, MTP has been built to only allow a single operation at a time (for example, read, write or delete operation), while no other operation can be executed until the previous operation is complete.

The message of the dolphin MTP operation should be better than "MTP died unexpectedly".
Comment 2 Mike Krutov 2018-07-15 12:11:51 UTC
Jamie, yep, that is the point - it took a while for me to figure out that amarok is the culprit which blocks MTP. Dolphin should check for amarok, then ask user if user wants to disable amarok MTP plugin instead of just saying that it was unable to mount MTP device.
Comment 3 Elvis Angelaccio 2018-07-21 09:28:27 UTC
It's not just Amarok. Open two dolphin processes and you will get the same crash.
Comment 4 Elvis Angelaccio 2018-07-21 09:35:52 UTC
Moving to kio-extras. The mtp ioslave should use a kded plugin to globally handle the MTP operations, so that different processes will be able to use mtp concurrently.
Comment 5 Jaime Torres 2018-07-21 09:58:24 UTC
Git commit 0cc17f0c1b91969d2e7dd5722086abc8b5105db9 by Jaime Torres.
Committed on 21/07/2018 at 09:58.
Pushed by jtamate into branch 'master'.

Avoid a kio-mtp crash when trying to add a blocked device to the device cache

Summary:
When the device is blocked, for example by amarok mtp plugin, the result of LIBMTP_Open_Raw_Device_Uncached(rawDevice) is nullptr and
LIBMTP_Get_Friendlyname(nullptr) crashes.

Avoid to create a cache for a device that can't be opened.

Test Plan:
With Amarok started and its mtp plugin enabled, plug in an android device.
Try to open it with dolphin, always the same kio backtrace:

```
==13233== Invalid read of size 8
==13233==    at 0x1087ABCE: LIBMTP_Get_Friendlyname (in /usr/lib64/libmtp.so.9.4.0)
==13233==    by 0x105EE67C: CachedDevice::CachedDevice(LIBMTP_mtpdevice_struct*, LIBMTP_raw_device_struct*, QString, int) (devicecache.cpp:44)
==13233==    by 0x105F0A30: DeviceCache::checkDevice(Solid::Device) (devicecache.cpp:150)
==13233==    by 0x105F1517: DeviceCache::DeviceCache(int, QObject*) (devicecache.cpp:94)
==13233==    by 0x105F2FC1: MTPSlave::MTPSlave(QByteArray const&, QByteArray const&) (kio_mtp.cpp:70)
==13233==    by 0x105F8BF9: kdemain (kio_mtp.cpp:54)
==13233==    by 0x4016CC: main (kioslave.cpp:130)
==13233==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
```
And in dolphin, the message: MTP died unexpectedly

After, the message: The file or folder udi=/org/kde/solid/udev/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1 does not exist.

Reviewers: #frameworks, elvisangelaccio

Reviewed By: elvisangelaccio

Subscribers: broulik

Differential Revision: https://phabricator.kde.org/D14158

M  +1    -1    mtp/devicecache.cpp

https://commits.kde.org/kio-extras/0cc17f0c1b91969d2e7dd5722086abc8b5105db9
Comment 6 Elvis Angelaccio 2018-08-16 08:51:21 UTC
*** Bug 383628 has been marked as a duplicate of this bug. ***
Comment 7 Elvis Angelaccio 2018-08-16 08:59:38 UTC
Git commit 6010d09233e5bb7a00606c44a2fbe5898ecc36e0 by Elvis Angelaccio, on behalf of Jaime Torres.
Committed on 16/08/2018 at 08:58.
Pushed by elvisangelaccio into branch 'Applications/18.08'.

Avoid a kio-mtp crash when trying to add a blocked device to the device cache

Summary:
When the device is blocked, for example by amarok mtp plugin, the result of LIBMTP_Open_Raw_Device_Uncached(rawDevice) is nullptr and
LIBMTP_Get_Friendlyname(nullptr) crashes.

Avoid to create a cache for a device that can't be opened.

Test Plan:
With Amarok started and its mtp plugin enabled, plug in an android device.
Try to open it with dolphin, always the same kio backtrace:

```
==13233== Invalid read of size 8
==13233==    at 0x1087ABCE: LIBMTP_Get_Friendlyname (in /usr/lib64/libmtp.so.9.4.0)
==13233==    by 0x105EE67C: CachedDevice::CachedDevice(LIBMTP_mtpdevice_struct*, LIBMTP_raw_device_struct*, QString, int) (devicecache.cpp:44)
==13233==    by 0x105F0A30: DeviceCache::checkDevice(Solid::Device) (devicecache.cpp:150)
==13233==    by 0x105F1517: DeviceCache::DeviceCache(int, QObject*) (devicecache.cpp:94)
==13233==    by 0x105F2FC1: MTPSlave::MTPSlave(QByteArray const&, QByteArray const&) (kio_mtp.cpp:70)
==13233==    by 0x105F8BF9: kdemain (kio_mtp.cpp:54)
==13233==    by 0x4016CC: main (kioslave.cpp:130)
==13233==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
```
And in dolphin, the message: MTP died unexpectedly

After, the message: The file or folder udi=/org/kde/solid/udev/sys/devices/pci0000:00/0000:00:14.0/usb1/1-1 does not exist.

Reviewers: #frameworks, elvisangelaccio

Reviewed By: elvisangelaccio

Subscribers: broulik

Differential Revision: https://phabricator.kde.org/D14158

M  +1    -1    mtp/devicecache.cpp

https://commits.kde.org/kio-extras/6010d09233e5bb7a00606c44a2fbe5898ecc36e0
Comment 8 Elvis Angelaccio 2018-08-16 09:02:43 UTC
*** Bug 383317 has been marked as a duplicate of this bug. ***
Comment 9 Elvis Angelaccio 2018-08-16 09:20:11 UTC
There is a workaround for this problem: use only one dolphin window (tabs are your friends!) to copy/move files to/from your phone. Everything else won't work:

- you cannot copy MTP files from dolphin to the desktop.
- you cannot open e.g. a PDF file from the MTP folder; copy it somewhere else first.
- you cannot open Amarok and dolphin at the same time.
- etc. etc.
Comment 10 Elvis Angelaccio 2018-08-16 09:20:21 UTC
*** Bug 379680 has been marked as a duplicate of this bug. ***
Comment 11 Elvis Angelaccio 2018-08-16 09:36:25 UTC
*** Bug 375840 has been marked as a duplicate of this bug. ***
Comment 12 Elvis Angelaccio 2018-08-16 09:41:39 UTC
*** Bug 356084 has been marked as a duplicate of this bug. ***
Comment 13 Elvis Angelaccio 2018-08-16 09:46:32 UTC
*** Bug 336399 has been marked as a duplicate of this bug. ***
Comment 14 Elvis Angelaccio 2018-08-16 09:53:09 UTC
*** Bug 350384 has been marked as a duplicate of this bug. ***
Comment 15 Elvis Angelaccio 2018-08-16 10:04:15 UTC
*** Bug 331682 has been marked as a duplicate of this bug. ***
Comment 16 Elvis Angelaccio 2018-08-16 10:05:23 UTC
*** Bug 325629 has been marked as a duplicate of this bug. ***
Comment 17 Elvis Angelaccio 2018-08-16 10:35:56 UTC
*** Bug 396271 has been marked as a duplicate of this bug. ***
Comment 18 Elvis Angelaccio 2018-08-16 10:38:04 UTC
*** Bug 359112 has been marked as a duplicate of this bug. ***
Comment 19 Elvis Angelaccio 2018-09-30 16:08:31 UTC
*** Bug 398989 has been marked as a duplicate of this bug. ***
Comment 20 Attila 2018-10-07 08:39:32 UTC
(In reply to Elvis Angelaccio from comment #19)
> *** Bug 398989 has been marked as a duplicate of this bug. ***

To me as a user I don't think that this is a duplicate of bug 398989.
In my case neither dolphin nor amarok is running.

The workaround doesn't work for me (comment 9).
Comment 21 Elvis Angelaccio 2018-10-07 11:36:48 UTC
(In reply to Attila from comment #20)
> The workaround doesn't work for me (comment 9).

Please make sure you have only *one* mtp.so process in ksysguard.
Comment 22 Attila 2018-10-07 12:13:55 UTC
(In reply to Elvis Angelaccio from comment #21)
> (In reply to Attila from comment #20)
> > The workaround doesn't work for me (comment 9).
> 
> Please make sure you have only *one* mtp.so process in ksysguard.

The "mtp" process is not running. Neither before I plug in the phone nor when the phone is conneted.
Comment 23 andreas.krutzler 2018-10-08 17:39:48 UTC
Git commit aaa1edbb74c4fb01affbde7b79bb45d3a9b61f83 by Andreas Krutzler.
Committed on 08/10/2018 at 17:39.
Pushed by akrutzler into branch 'master'.

[mtp] Move MTP device handling from kioslave to kiod-module

Summary:
Consult T9390 for more information.
Related: bug 319880, bug 325924, bug 336456, bug 372860, bug 382046, bug 383314

Closes T9390

Reviewers: elvisangelaccio, ltoscano, hetzenecker, dfaure, mlaurent

Reviewed By: elvisangelaccio, dfaure, mlaurent

Subscribers: mlaurent, kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Maniphest Tasks: T9390

Differential Revision: https://phabricator.kde.org/D15277

M  +5    -5    mtp/CMakeLists.txt
D  +0    -229  mtp/devicecache.cpp
D  +0    -86   mtp/devicecache.h
D  +0    -73   mtp/filecache.cpp
D  +0    -81   mtp/filecache.h
M  +483  -576  mtp/kio_mtp.cpp
M  +14   -8    mtp/kio_mtp.h
D  +0    -358  mtp/kio_mtp_helpers.cpp
D  +0    -46   mtp/kio_mtp_helpers.h
A  +19   -0    mtp/kiod_module/CMakeLists.txt
A  +171  -0    mtp/kiod_module/kmtpd.cpp     [License: GPL (v2+)]
A  +63   -0    mtp/kiod_module/kmtpd.h     [License: GPL (v2+)]
A  +12   -0    mtp/kiod_module/kmtpd.json
A  +127  -0    mtp/kiod_module/mtpdevice.cpp     [License: GPL (v2+)]
A  +78   -0    mtp/kiod_module/mtpdevice.h     [License: GPL (v2+)]
A  +635  -0    mtp/kiod_module/mtpstorage.cpp     [License: GPL (v2+)]
A  +142  -0    mtp/kiod_module/mtpstorage.h     [License: GPL (v2+)]
A  +21   -0    mtp/shared/CMakeLists.txt
A  +70   -0    mtp/shared/kmtpdeviceinterface.cpp     [License: LGPL]
A  +64   -0    mtp/shared/kmtpdeviceinterface.h     [License: LGPL]
A  +85   -0    mtp/shared/kmtpdinterface.cpp     [License: LGPL]
A  +70   -0    mtp/shared/kmtpdinterface.h     [License: LGPL]
A  +147  -0    mtp/shared/kmtpfile.cpp     [License: LGPL]
A  +90   -0    mtp/shared/kmtpfile.h     [License: LGPL]
A  +98   -0    mtp/shared/kmtpstorageinterface.cpp     [License: LGPL]
A  +77   -0    mtp/shared/kmtpstorageinterface.h     [License: LGPL]
A  +50   -0    mtp/shared/org.kde.kmtp.daemon.xml
A  +62   -0    mtp/shared/org.kde.kmtp.device.xml
A  +154  -0    mtp/shared/org.kde.kmtp.storage.xml

https://commits.kde.org/kio-extras/aaa1edbb74c4fb01affbde7b79bb45d3a9b61f83
Comment 24 Elvis Angelaccio 2018-11-02 11:20:36 UTC
*** Bug 363593 has been marked as a duplicate of this bug. ***
Comment 25 Elvis Angelaccio 2018-11-20 21:06:45 UTC
*** Bug 401235 has been marked as a duplicate of this bug. ***
Comment 26 Elvis Angelaccio 2019-01-15 15:58:24 UTC
*** Bug 403198 has been marked as a duplicate of this bug. ***
Comment 27 Christoph Feck 2019-02-22 14:29:25 UTC
*** Bug 404087 has been marked as a duplicate of this bug. ***