Bug 387447

Summary: KDE Connect file transfers do not finish for small files
Product: [Applications] kdeconnect Reporter: Matthijs Tijink <matthijstijink>
Component: commonAssignee: Albert Vaca Cintora <albertvaka>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 1.2   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Matthijs Tijink 2017-11-29 19:36:24 UTC
On current kdeconnect (1.2 from Arch linux package / master compiled) I cannot transfer small files (< 1200 bytes, although there is no exact limit) from my phone to the desktop. It seems to be related to the payload transfer code, since this also happens when notifications with small icons are transferred (but this is harder to reproduce).

I bisected the issue to d1d84bc464c5f85268a9a1229c8a46ef20367cff (Fix DownloadJob not finishing).

To reproduce:
 - In the KDE Connect android app, select a small file to transfer (in my example, 28 bytes).
 - On android, the notification about the transferred file appears, saying it was transferred successfully. The logcat also says that all 28 bytes were transferred successfully.
 - On the desktop, the below log appears (and no further entries) and the transferring file notification appears and does not stop spinning. A "small_file.txt.part" file appears, with size 0 bytes.
 - Killing either the android app or desktop daemon stops the transfer and deletes the .part file, without creating the final file.

The log created by /usr/lib/kdeconnected:

kdeconnect.core: KdeConnect daemon starting
kdeconnect.core: onStart
kdeconnect.core: KdeConnect daemon started
kdeconnect.core: Broadcasting identity packet
kdeconnect.core: Starting client ssl (but I'm the server TCP socket)
kdeconnect.core: Socket succesfully stablished an SSL connection
kdeconnect.core: It is a known device "G4"
kdeconnect.core: Not loading plugin "kdeconnect_remotecommands" because device doesn't support it
Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
kdeconnect.plugin.mpris: MPRIS service "org.mpris.MediaPlayer2.mplayer" just came online
kdeconnect.plugin.mpris: Mpris addPlayer "org.mpris.MediaPlayer2.mplayer" -> "Mplayer"
kdeconnect.plugin.sftp: add to dolphin
kdeconnect.plugin.sftp: Created device: "G4"
kdeconnect.plugin.share: File transfer
kdeconnect.core: FileTransferJob Downloading payload to QUrl("file:///home/matthijs/small_file.txt") size: 28

When debugging myself, I discovered several things which may be of use:
 - When adding a Thread.sleep(500) in the android payload transfer code (LanLink::sendPackageInternal), directly after outputStream.flush(), the transfer is successfull. The same Thread.sleep(500) works when put after outputStream.flush(), outputStream.close() or after SslHelper.convertToSslSocket() when combined with payloadSocket.sendHandshake().
 - When trying to read all bytes directly (by using m_origin->readAll() and m_origin->waitForReadyRead() in FileTransferJob::startTransfer() directly before the QNAM::put() call), only the first byte is reported back.
Comment 1 Christoph Feck 2017-12-19 23:49:21 UTC
A fix for bug 386246 was just committed. It is possibly a duplicate. Please test when packages are updated including the referenced commit.
Comment 2 Matthijs Tijink 2017-12-20 10:11:39 UTC
I just tested it, it indeed solves the bug!