Bug 450198 - SFTP uses cache-based mode instead of FileJob-based
Summary: SFTP uses cache-based mode instead of FileJob-based
Status: RESOLVED FIXED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: SFTP (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-14 08:56 UTC by Tomas Janco
Modified: 2022-02-26 16:02 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Janco 2022-02-14 08:56:17 UTC
SUMMARY
Recently (I suspect since v5.0) I started experiencing long delays when opening a video file via sftp:// url in VLC via kio-fuse. The file starts opening and does not play for tens of seconds to minutes. The larger the file, the longer the delay. This does not happen on smb:// urls.

I have found out, via SFTP kio-fuse downloads the whole file before it starts playing.
I have confirmed this by running 

```
killall kio-fuse; export QT_LOGGING_RULES="org.kde.kio.fuse.debug=true;kf5.kio.core.*=true;log_kio_sftp=true;log_kio_sftp.trace=true"; /usr/lib64/libexec/kio-fuse -d
```

When using SMB, the output contains:
```
org.kde.kio.fuse: Reading 131072 byte(s) at offset 626688 of (FileJob-based) node "filename-redacted.mp4"
```

However when using SFTP it contains:
```
org.kde.kio.fuse: Reading 4096 byte(s) at offset 32768 of (cache-based) node "filename-redacted.mp4"
```

The `--disable-filejob-io` is not set. When I set it, even SMB uses the cache and downloads the whole file before playing.

The filejob/cache mode selection boils down to this condition
https://github.com/KDE/kio-fuse/blob/master/kiofusevfs.cpp#L1861
But SFTP should support both opening and truncating.


STEPS TO REPRODUCE
1. Open a video file on sftp:// URL

OBSERVED RESULT
Video starts playing after a long delay. The delay is longer for bigger file sizes. The file is fully downloaded before it starts playing.

EXPECTED RESULT
The video should start playing immediately. (As it does with smb:// urls)

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Gentoo, 5.15.16-gentoo-x86_64
KDE Plasma Version: 5.23.5
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2
KIO FUSE version 5.0.0
FUSE library version 3.10.5
using FUSE kernel interface version 7.31
fusermount3 version: 3.10.5
kio-extras version: 21.08.3-r1

ADDITIONAL INFORMATION
Comment 1 Fabian Vogt 2022-02-14 10:53:17 UTC
Looks like KIO's protocoltojson tool is missing support for the "truncating" property, so it got lost when porting from sftp.protocol to sftp.json.

So this needs fixing in protocoltojson as well as all affected .json files.
Comment 2 Tomas Janco 2022-02-14 10:59:07 UTC
But also truncating should not be required for opening a file in read mode via kio-fuse.
Comment 3 Fabian Vogt 2022-02-14 11:03:35 UTC
(In reply to Tomas Janco from comment #2)
> But also truncating should not be required for opening a file in read mode
> via kio-fuse.

IMO it's even more surprising behaviour if opening a file O_RDWR results in entirely different semantics than O_RDONLY.
Comment 4 Tomas Janco 2022-02-16 07:57:00 UTC
I created merge requests for the required changes:
https://invent.kde.org/frameworks/kio/-/merge_requests/758
https://invent.kde.org/network/kio-extras/-/merge_requests/143
Comment 5 Fabian Vogt 2022-02-26 16:02:14 UTC
MRs got merged, closing.