qBittorrent icon indicating copy to clipboard operation
qBittorrent copied to clipboard

When disk is approaching full, prevent errors by first slowing down, and then stopping

Open wambiditu opened this issue 2 years ago • 3 comments

Suggestion

When a disk (for temporary downloads and/or for completed downloads) is becoming nearly full (say, within 1 GB free), qBittorrent could:

  • use alternative speed limits, or other restricted speed limit for all downloads, OR
  • use alternative speed limits, or other restricted speed limit for torrents downloading or moving to affected disk

When a disk is nearer to being full (say, within 100 MB), or is actually full, qBittorrent could:

  • cease downloading anything until sufficient disk space is freed, OR
  • cease downloading (or moving) anything to the affected disk until sufficient disk space is freed, OR
  • pause all affected torrents individually (losing any information about which torrents the user had paused)

In each case, the GUI could indicate that a disk is running out of space. The triggering sizes could be user-adjustable, although that doesn't seem really necessary just to get this mechanism working.

Use case

This would be most applicable to the case where file space is not pre-allocated.

The behavior in 4.4.1 appears to be to attempt to write to the disk, no matter how full it is, and regardless of whether writing to the same disk has already just failed. In my case, this is resulting in many torrents suddenly having an error status such as "Errored: Bad address", which sounds like a serious disk failure, rather than an expected disk full condition. (I'm on Ubuntu 22.04 LTS)

The goal would be to give the user time to resolve the situation, or for other actions to free up space, such as by qBittorrent moving completed files as usual (say from a crowded temporary location, to a less-crowded completed location). The goal would also be to prevent filling the disk, and prevent torrent errors.

Extra info/examples/attachments

No response

wambiditu avatar Jun 01 '22 16:06 wambiditu

A simple logic would be to test the free disk space on the downloadPath() root and ensure we have enough space to spare.

Just testing this block, tied to a QTimer

QStorageInfo Session::downloadPathStorageInfo()
{
    QStorageInfo infoRoot(QDir(downloadPath()).rootPath());

    return infoRoot;
}

void Session::checkDiskSpace()
{
    QStorageInfo infoRoot = downloadPathStorageInfo();

    LogMsg(tr("Free disk space of \"%1\" %2 available, current download rate is %3").arg(
        infoRoot.rootPath(),
        Utils::Misc::friendlyUnit(infoRoot.bytesAvailable()),
        Utils::Misc::friendlyUnit(m_status.downloadRate, true)
    ),
        Log::INFO);

    // if disk space is running below 8Gb, force download speed to 0, and I can keep uploading
    if (infoRoot.bytesFree() < ((qint64)8 * 1024 * 1024 * 1024)) {
        lt::settings_pack settingsPack = m_nativeSession->get_settings();
        settingsPack.set_int(lt::settings_pack::download_rate_limit, 56 * 1024); // actually 0 is unlimited
        m_nativeSession->apply_settings(settingsPack);

        LogMsg(tr("Disk space low, download speed set to 0"), Log::INFO);
    }

See commit https://github.com/itlezy/qBittorrent/commit/695688c24feeb2e9ef9e7ebcf7f86c82168d751f and more recent commit with free disk space in status bar https://github.com/itlezy/qBittorrent/commit/9cb5b116499b0da2eeac6e0337b184c7f1cae7b4

itlezy avatar Jun 07 '22 14:06 itlezy

  • pause all affected torrents individually (losing any information about which torrents the user had paused)

Better set error with reason "no disk space".

DarkVoyage avatar Jun 09 '22 10:06 DarkVoyage

  • pause all affected torrents individually (losing any information about which torrents the user had paused)

Better set error with reason "no disk space".

Even better: make a pop-up appear; either requiring from user to OK it or in a non intrusive way [e.g. being minimized to Taskbar] - accordingly to users pre-choice of behavior

GitHubinatrix avatar May 14 '23 13:05 GitHubinatrix