Repository navigation
fix: bind index lifecycle to daemon via D-Bus name watcher - #294
Conversation
1. Root cause: index did not monitor the daemon's D-Bus name on the system bus; when daemon stopped, index kept running with its session-bus names registered, so dde-file-manager's QDBusServiceWatcher never fired serviceUnregistered and UI stayed "updating" instead of showing an error state 2. Fix: add QDBusServiceWatcher in main() watching org.deepin.Anything on the system bus for serviceUnregistered; on trigger, unregister index session-bus names and exit so dde-file-manager detects the name unregistration and switches UI to error state 3. Impact: index now exits when daemon disappears; on daemon recovery index is D-Bus-activated again and reconnects; normal shutdown unaffected (SIGTERM handler and atexit already call unregisterIndexServices) Log: index exits when daemon stops, UI shows error state Influence: 1. Test: start daemon + index, stop daemon, verify index exits and UI shows error state 2. Test: restart daemon, verify index restarts and reconnects 3. Test: normal restart/shutdown unaffected fix: 通过D-Bus名称监视绑定index与daemon生命周期 1. 根因:index未监视daemon在系统总线的D-Bus名称,daemon停止时 index仍保持会话总线名称注册,文管的QDBusServiceWatcher不触发 serviceUnregistered,UI仍显示"更新中"而非错误状态 2. 方案:在main()中添加QDBusServiceWatcher监听系统总线上 org.deepin.Anything的serviceUnregistered信号,触发时注销index 会话总线名称并退出,文管检测到名称注销后切换UI为错误状态 3. 影响:daemon消失时index退出;daemon恢复时index通过D-Bus激活 重启并重连;正常关机重启不受影响 Log: daemon停止时index退出,UI显示错误状态 Influence: 1. 测试:启动daemon和index,停止daemon,验证index退出且UI显示错误 2. 测试:重启daemon,验证index重启并重连 3. 测试:正常重启关机不受影响 PMS: BUG-377687
Reviewer's GuideImplementationAdd a system-bus watcher that unregisters the index services and exits when the daemon disappears.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/index/main.cpp" line_range="142" />
<code_context>
+ // existing QDBusServiceWatcher detects the index name unregistration and
+ // switches the UI to an error state. When the daemon restarts the index
+ // is D-Bus-activated again and re-establishes the VFS monitor connection.
+ auto *daemonWatcher = new QDBusServiceWatcher(
+ QStringLiteral("org.deepin.Anything"),
+ QDBusConnection::systemBus(),
</code_context>
<issue_to_address>
**Index stays available without daemon**
When the index is activated while the daemon is absent, or the daemon disappears after service registration but before watcher installation, `daemonWatcher` only reports later unregistrations, so `main()` leaves the session-bus names registered. After an initial `initDispatcher()` failure, its watcher is also deleted and the index cannot reconnect, leaving the index presented as available and the file manager stuck updating.
Check whether the daemon currently owns the name when setting up the watcher, and handle an unregistration that races with watcher installation.
Also at `src/index/main.cpp:143-146`.
</issue_to_address>
### Comment 2
<location path="src/index/main.cpp" line_range="152" />
<code_context>
+ qWarning() << "deepin-anything-index: daemon (org.deepin.Anything) "
+ "disappeared on system bus, exiting to maintain "
+ "lifecycle binding";
+ anything_index::unregisterIndexServices();
+ QCoreApplication::exit(0);
+ });
</code_context>
<issue_to_address>
**Outage changes stay unindexed**
When the daemon disappears while no indexing work is pending and files change before the index starts again, `unregisterIndexServices()` follows normal cleanup, leaving the index clean and removing the sentinel. On reactivation, `handleSilentStart()` skips the compensating update, so outage changes remain absent or stale in search results.
Preserve a dirty state or sentinel on this exit so reactivation runs the compensating update.
</issue_to_address>
### Comment 3
<location path="src/index/main.cpp" line_range="154" />
<code_context>
+ "lifecycle binding";
+ anything_index::unregisterIndexServices();
+ QCoreApplication::exit(0);
+ });
+
// Safety net: ensure cleanup runs even when the process exits via C exit()
</code_context>
<issue_to_address>
**Sibling services cannot reactivate index**
When the daemon recovers and a client requests OCR or filename indexing before making a request to TextIndex, the index exits successfully after daemon unregistration, but only `org.deepin.Filemanager.TextIndex` has a D-Bus activation file. If a client next requests only the OCR or filename service, D-Bus cannot reactivate the index, so that request fails even after the daemon has recovered.
Provide D-Bus activation entries for the OCR and filename service names, or otherwise ensure requests to those names start the index process.
</issue_to_address>
### Comment 4
<location path="src/index/main.cpp" line_range="142" />
<code_context>
+ // existing QDBusServiceWatcher detects the index name unregistration and
+ // switches the UI to an error state. When the daemon restarts the index
+ // is D-Bus-activated again and re-establishes the VFS monitor connection.
+ auto *daemonWatcher = new QDBusServiceWatcher(
+ QStringLiteral("org.deepin.Anything"),
+ QDBusConnection::systemBus(),
</code_context>
<issue_to_address>
**Variable naming rule is broken**
The new `daemonWatcher` local uses camelCase, violating the required snake_case naming convention.
Rename the local to `daemon_watcher`.
</issue_to_address>| // existing QDBusServiceWatcher detects the index name unregistration and | ||
| // switches the UI to an error state. When the daemon restarts the index | ||
| // is D-Bus-activated again and re-establishes the VFS monitor connection. | ||
| auto *daemonWatcher = new QDBusServiceWatcher( |
There was a problem hiding this comment.
🟡 Medium · Index stays available without daemon
When the index is activated while the daemon is absent, or the daemon disappears after service registration but before watcher installation, daemonWatcher only reports later unregistrations, so main() leaves the session-bus names registered. After an initial initDispatcher() failure, its watcher is also deleted and the index cannot reconnect, leaving the index presented as available and the file manager stuck updating.
Check whether the daemon currently owns the name when setting up the watcher, and handle an unregistration that races with watcher installation.
Also at src/index/main.cpp:143-146.
Prompt for AI agents
In `src/index/main.cpp` at line 142:
**Index stays available without daemon**
When the index is activated while the daemon is absent, or the daemon disappears after service registration but before watcher installation, `daemonWatcher` only reports later unregistrations, so `main()` leaves the session-bus names registered. After an initial `initDispatcher()` failure, its watcher is also deleted and the index cannot reconnect, leaving the index presented as available and the file manager stuck updating.
Check whether the daemon currently owns the name when setting up the watcher, and handle an unregistration that races with watcher installation.
Also at `src/index/main.cpp:143-146`.| qWarning() << "deepin-anything-index: daemon (org.deepin.Anything) " | ||
| "disappeared on system bus, exiting to maintain " | ||
| "lifecycle binding"; | ||
| anything_index::unregisterIndexServices(); |
There was a problem hiding this comment.
🟠 High · Outage changes stay unindexed
When the daemon disappears while no indexing work is pending and files change before the index starts again, unregisterIndexServices() follows normal cleanup, leaving the index clean and removing the sentinel. On reactivation, handleSilentStart() skips the compensating update, so outage changes remain absent or stale in search results.
Preserve a dirty state or sentinel on this exit so reactivation runs the compensating update.
Prompt for AI agents
In `src/index/main.cpp` at line 152:
**Outage changes stay unindexed**
When the daemon disappears while no indexing work is pending and files change before the index starts again, `unregisterIndexServices()` follows normal cleanup, leaving the index clean and removing the sentinel. On reactivation, `handleSilentStart()` skips the compensating update, so outage changes remain absent or stale in search results.
Preserve a dirty state or sentinel on this exit so reactivation runs the compensating update.| "lifecycle binding"; | ||
| anything_index::unregisterIndexServices(); | ||
| QCoreApplication::exit(0); | ||
| }); |
There was a problem hiding this comment.
🟡 Medium · Sibling services cannot reactivate index
When the daemon recovers and a client requests OCR or filename indexing before making a request to TextIndex, the index exits successfully after daemon unregistration, but only org.deepin.Filemanager.TextIndex has a D-Bus activation file. If a client next requests only the OCR or filename service, D-Bus cannot reactivate the index, so that request fails even after the daemon has recovered.
Provide D-Bus activation entries for the OCR and filename service names, or otherwise ensure requests to those names start the index process.
Prompt for AI agents
In `src/index/main.cpp` at line 154:
**Sibling services cannot reactivate index**
When the daemon recovers and a client requests OCR or filename indexing before making a request to TextIndex, the index exits successfully after daemon unregistration, but only `org.deepin.Filemanager.TextIndex` has a D-Bus activation file. If a client next requests only the OCR or filename service, D-Bus cannot reactivate the index, so that request fails even after the daemon has recovered.
Provide D-Bus activation entries for the OCR and filename service names, or otherwise ensure requests to those names start the index process.| // existing QDBusServiceWatcher detects the index name unregistration and | ||
| // switches the UI to an error state. When the daemon restarts the index | ||
| // is D-Bus-activated again and re-establishes the VFS monitor connection. | ||
| auto *daemonWatcher = new QDBusServiceWatcher( |
There was a problem hiding this comment.
⚪ Low · Variable naming rule is broken
The new daemonWatcher local uses camelCase, violating the required snake_case naming convention.
Rename the local to daemon_watcher.
Prompt for AI agents
In `src/index/main.cpp` at line 142:
**Variable naming rule is broken**
The new `daemonWatcher` local uses camelCase, violating the required snake_case naming convention.
Rename the local to `daemon_watcher`.From AGENTS.md L59:
- Variables: `snake_case` (e.g., `config_ptr`, `event_handler`)
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本报告由 AI 代码审查工具自动生成 |
|
/merge |
Root Cause Analysis
When
deepin-anything-daemonstops or crashes,deepin-anything-indexcontinues running with its session-bus D-Bus names still registered.dde-file-managerusesQDBusServiceWatcherto monitor index names on the session bus; since the index process never exits,serviceUnregisterednever fires and the UI stays stuck in "updating" instead of switching to an error state. The root cause is that index does not monitor the daemon's system-bus name (org.deepin.Anything), so it cannot detect daemon disappearance and exit accordingly.Fix Approach
Add a
QDBusServiceWatcherinsrc/index/main.cppwatchingorg.deepin.Anythingon the system bus forserviceUnregistered. When the daemon disappears, the watcher callback callsunregisterIndexServices()(releases session-bus names) and thenQCoreApplication::exit(0), causing the index process to exit. dde-file-manager's existing index name watcher then detectsserviceUnregisteredand switches the UI to error state. On daemon recovery, the index is D-Bus-activated again and reconnects.Change Safety Assessment
Code Safety
main()— no existing function signatures modified, no public functions removed, no existing call paths altered. The watcher callback callsunregisterIndexServices()(existing, idempotent) andQCoreApplication::exit(0), which integrates with the existing atexit handler and sentinel cleanup.Business Impact Scope
Affected module:
deepin-anything-indexprocess lifecycle. User scenario: when the indexing daemon stops unexpectedly (crash, OOM, manual stop), the index process now exits cleanly instead of lingering with stale D-Bus names. dde-file-manager's UI correctly transitions to an error state instead of showing perpetual "updating". Normal shutdown/restart is unaffected (SIGTERM handler and atexit already callunregisterIndexServices).Verification Suggestion
根因分析
当
deepin-anything-daemon停止或崩溃时,deepin-anything-index仍继续运行,其会话总线 D-Bus 名称仍保持注册。dde-file-manager通过QDBusServiceWatcher监视会话总线上的 index 名称;由于 index 进程不退出,serviceUnregistered不触发,UI 一直显示"更新中"而不切换到错误状态。根因是 index 未监视 daemon 的系统总线名称(org.deepin.Anything),无法感知 daemon 消失并退出。修复方案
在
src/index/main.cpp中新增QDBusServiceWatcher,监听系统总线上org.deepin.Anything的serviceUnregistered信号。daemon 消失时,watcher 回调调用unregisterIndexServices()(释放会话总线名称)后执行QCoreApplication::exit(0),index 进程退出。文管现有的 index 名称 watcher 随即检测到serviceUnregistered,切换 UI 为错误状态。daemon 恢复后 index 通过 D-Bus 激活重启并重连。改动安全评估
代码安全评估
main()中新增 watcher 代码块,不修改已有函数签名、不删除公开函数、不影响已有调用路径。回调调用的unregisterIndexServices()为已有幂等函数,QCoreApplication::exit(0)经 Qt 事件循环正常退出,与现有 atexit handler 和 sentinel 清理机制互补不冲突。业务影响范围
受影响模块:
deepin-anything-index进程生命周期。用户场景:索引 daemon 异常停止(崩溃、OOM、手动停止)时,index 进程现在会干净退出,而非带着过时的 D-Bus 名称继续运行。文管 UI 正确切换到错误状态,而非一直显示"更新中"。正常关机重启不受影响。验证建议
Summary by Sourcery
Make the index process follow the daemon’s D-Bus lifecycle so daemon failures are reflected promptly in the file manager.
Bug Fixes:
Enhancements: