Skip to content

fix: add watchdog timer for mkfs progress stuck at 99% - #49

Draft
tianming-1996 wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
tianming-1996:fix/bug-291279
Draft

tianming-1996 wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
tianming-1996:fix/bug-291279

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Oct 29, 2026 •

Copy link
Copy Markdown

fix: add watchdog timer for mkfs progress stuck at 99%

Root Cause

When formatting large drives (1TB+ ext3) via dde-device-formatter, the mkfs quick format path uses a simulated progress timer (step 0.06 / 300ms interval) that caps at 0.99 (99%). The only path to 100% is the DUDisksJob::completed signal. For large drives, mkfs.ext3 takes a very long time and the UDisks2 DBus job object may become invalid, causing the completed signal to never fire — leaving the progress bar permanently stuck at 99%.

Source evidence: view/mainwindow.cpp:135 — setProgress(0.99) hardcoded cap; view/mainwindow.cpp:140 — DUDisksJob::completed is the only path to setProgress(1).

Fix

Added a watchdog timer inside the mkfs simulation progress lambda: when m_simulationProgressValue >= 1 (progress reached 0.99), the timer switches to a 5-second interval and checks if the mkfs process is still running via pgrep mkfs. If mkfs has exited (pgrep returns exit code 1), the timer stops, sets progress to 1, disconnects the job, and calls onFormatingFinished(true) to complete the formatting flow.

The normal path (DUDisksJob::completed signal fires normally) is completely unaffected — the watchdog only activates when the signal fails to arrive.

Change Safety

  • Risk Level: Low
  • Change adds watchdog logic inside existing mkfs simulation timer lambda; no signature changes, no public API changes
  • Target lines are original code, not a previous bug fix product — this change does not revert any historical fix
  • Related PMS bugs (325935, 296699, 215025) do not involve the mkfs progress timer logic

Business Impact Scope

  • Quick format (mkfs) progress display for USB drives / external hard drives
  • Normal formatting path unaffected; watchdog only activates when DUDisksJob::completed signal fails to arrive
  • Non-quick format (erase operation) unaffected

Verification Suggestion

Test small USB drive quick formatting (normal path) and large drive (1TB+) ext3 formatting (watchdog path).


根因分析

使用 dde-device-formatter 格式化大容量磁盘(1TB+ ext3)时,mkfs 快速格式化使用模拟进度计时器(步长 0.06 / 300ms 间隔),上限固定为 0.99(99%)。唯一推进到 100% 的路径是 DUDisksJob::completed 信号。大容量磁盘 mkfs.ext3 耗时极长,UDisks2 DBus job 对象可能失效,导致 completed 信号不触发,进度条永久卡在 99%。

源码证据:view/mainwindow.cpp:135 — setProgress(0.99) 硬编码上限;view/mainwindow.cpp:140 — DUDisksJob::completed 是唯一推进到 setProgress(1) 的路径。

修复方案

在 mkfs 模拟进度计时器 lambda 内新增看门狗逻辑:当 m_simulationProgressValue >= 1(进度到达 0.99)时,计时器切换为 5 秒间隔,通过 pgrep mkfs 检测 mkfs 进程是否仍在运行;若 mkfs 已退出(pgrep 返回退出码 1),则停止计时器、设置进度为 1、断开 job 连接并调用 onFormatingFinished(true) 完成格式化流程。

正常路径(DUDisksJob::completed 信号正常触发)完全不受影响——看门狗仅在信号未到达时激活。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 改动在现有 mkfs 模拟进度计时器 lambda 内新增看门狗逻辑,无签名变更、无公开 API 变更
  • 目标行为为原始代码,非历史 bug 修复产物,本次改动不撤销任何已有修复
  • 关联 PMS bug(325935、296699、215025)均不涉及 mkfs 进度计时器逻辑

业务影响范围

  • 快速格式化(mkfs)进度显示:U 盘 / 移动硬盘快速格式化(ext3/ext4/vfat)时的进度条显示
  • 正常格式化路径不受影响,看门狗仅在 completed 信号未到达时激活
  • 非快速格式化(erase 操作)不受影响

验证建议

测试小容量 U 盘快速格式化(正常路径)和大容量硬盘(1TB+)ext3 格式化(看门狗路径)。

Summary by Sourcery

Add watchdog handling to ensure mkfs formatting either completes or reports failure when progress reaches 99% without a completion signal.

Bug Fixes:

  • Prevent quick-format progress from remaining stuck at 99% when the mkfs completion signal is not delivered by completing successfully after the mkfs process exits.
  • Fail the formatting flow after a bounded watchdog timeout when the mkfs process does not exit.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tianming-1996

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tianming-1996
tianming-1996 marked this pull request as draft October 29, 2026 03:45
@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR prevents large-drive mkfs quick formatting from remaining stuck at 99% by adding a 5-second watchdog after simulated progress reaches its cap; it detects mkfs termination with pgrep and completes formatting through the existing success path, while leaving normal job-signal and non-mkfs flows unchanged.

Sequence diagram for the mkfs progress watchdog

sequenceDiagram
    participant Timer as QTimer
    participant Page as FormattingPage
    participant Mkfs as mkfs
    participant Job as DUDisksJob
    participant Main as MainWindow

    Timer->>Page: setProgress(progress < 1)
    Timer->>Timer: start(5000) when progress reaches cap
    loop Every 5 seconds
        Timer->>Mkfs: pgrep mkfs
        alt mkfs still running
            Mkfs-->>Timer: exit code 0
        else mkfs has exited
            Mkfs-->>Timer: exit code 1
            Timer->>Timer: stop()
            Timer->>Page: setProgress(1)
            Timer->>Job: disconnect()
            Timer->>Main: onFormatingFinished(true)
        end
    end

    Job-->>Main: completed()
    Main->>Page: setProgress(1)
Loading

File-Level Changes

Change Details Files
Adds a watchdog fallback for mkfs quick-format operations that reach the simulated 99% progress cap without receiving the UDisks job completion signal.
  • Adds QProcess usage to probe for running mkfs processes.
  • Keeps the simulation timer at 300 ms until 99%, then changes it to a 5-second polling interval.
  • When mkfs is no longer running, completes the progress UI, disconnects the job, and invokes the existing formatting-completion flow.
view/mainwindow.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

1. Root cause: mkfs quick format uses simulated progress timer that
   caps at 0.99; completion relies solely on DUDisksJob::completed
   signal which may not fire for large drives (1TB+ ext3)
2. Fix: after progress reaches 0.99, start a 5s watchdog timer that
   checks if the specific device's mkfs process is still running via
   pgrep -f with the device path; if exited, force-complete the flow
3. Impact: only activates when completed signal fails to arrive;
   normal formatting path is unaffected; watchdog has 5min max retry

Log: fix format progress stuck at 99% for large drives

Influence:
1. Test formatting with small USB drive (normal path)
2. Test formatting with large drive (1TB+) using ext3
3. Verify progress completes to 100% when mkfs finishes
4. Test concurrent formatting of multiple devices

fix: 修复大容量磁盘格式化进度卡在99%的问题

1. 根因:mkfs快速格式化使用模拟进度计时器,上限为0.99;完成
   仅依赖DUDisksJob::completed信号,大容量磁盘(1TB+)该信号可能不触发
2. 方案:进度到达0.99后启动5秒看门狗计时器,通过pgrep -f结合
   设备路径检测对应mkfs进程是否退出;若已退出则强制完成格式化流程
3. 影响:仅在completed信号未到达时激活,不影响正常格式化路径;
   看门狗最大重试5分钟后超时失败

Log: 修复大容量磁盘格式化进度卡在99%的问题

Influence:
1. 测试小容量U盘格式化(正常路径)
2. 测试大容量磁盘(1TB+) ext3格式化
3. 验证mkfs完成后进度能推进到100%
4. 测试多设备并发格式化场景

Bug: #291279
@github-actions

Copy link
Copy Markdown

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议。
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

deepin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants