Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QStorageInfo::mountedVolumes() hanging forever on Linux



  • Hello.

    Looking at this very simple program:

    #include <QCoreApplication>
    #include <QStorageInfo>
    #include <iostream>
    
    int main(int argc, char *argv[])
    {
        Q_UNUSED(argc)
        Q_UNUSED(argv)
    
        std::cout << "Before mounted volumes" << std::endl;
    
        auto volumes = QStorageInfo::mountedVolumes();
    
        std::cout << "After mounted volume" << std::endl;
        
        return 0;
    }
    

    For some unknown reason, the QStorageInfo::mountedVolumes() method freezes and is hanging forever. I let it run for several minutes, but the function did not return anything.

    Qt version: 5.12.0
    uname -a: Linux RD1 4.4.0-142-generic #168-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    Do you have any idea why it would hang like this? Anything I can do to resolve it or investigate the issue?

    Thanks.


  • Moderators

    Hi @ADGB
    could you try with 5.12.1 ?
    5.12.0 has a lot of bugs, some of them fundamental.

    .1 has over 300 bug fixes, maybe this is one of them.


  • Lifetime Qt Champion

    @ADGB Run it with strace:

    strace ./your_app
    

    and put the output here - maybe we can see where exactly it is hanging.



  • Thanks @J-Hilk and @jsulm for the quick responses.

    The issue came from a device which was not properly mounted.

    strace was hanging here:

    [...]
    getcwd("/home/myself/build-mountedvolumes-Desktop-Debug", 4096) = 50
    lstat("/home/myself/build-mountedvolumes-Desktop-Debug/systemd-1", 0x7ffcc45c5d70) = -1 ENOENT (No such file or directory)
    open("/dev/disk/by-label", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
    read(3, "nproto=5,maxproto=5,direct\n93 20"..., 1024) = 1024
    lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    lstat("/home/user", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    lstat("/home/user/SSD211", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
    open("/proc/self/mountinfo", O_RDONLY|O_CLOEXEC) = 4
    fstat(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
    read(4, "18 24 0:17 / /sys rw,nosuid,node"..., 1024) = 1024
    read(4, "s-agent,name=systemd\n30 18 0:24 "..., 1024) = 1024
    read(4, "oexec,relatime shared:21 - cgrou"..., 1024) = 1024
    read(4, "nproto=5,maxproto=5,direct\n93 20"..., 1024) = 1024
    read(4, "user/SSD212 rw,relatime share"..., 1024) = 536
    read(4, "", 1024)                       = 0
    close(4)                                = 0
    statfs("/home/user/SSD211", ^C
    

    This happened because [Automount] and [Mount] directives in our systemd services failed but left the device in a unstable state. Or maybe that the service was just hanging and no releasing the device while trying to mount it, preventing QStorageInfo::mountedVolumes() to access the device.

    Thanks again for your help!


Log in to reply