fix: prevent dde-apps crash when restarting due to concurrent model u… - #1683
fix: prevent dde-apps crash when restarting due to concurrent model u…#1683Ivy233 wants to merge 1 commit into
Conversation
|
Skipping CI for Draft Pull Request. |
Reviewer's GuideFixes a crash caused by concurrent access to AMAppItemModel by moving D-Bus object retrieval back to the main thread and making AppGroupManager’s reference model handling safe against destruction and readiness issues. Sequence diagram for AMAppItemModel D-Bus loading on main threadsequenceDiagram
participant AMAppItemModel
participant ObjectManager
participant QDBusPendingCallWatcher
AMAppItemModel->>ObjectManager: GetManagedObjects()
ObjectManager-->>AMAppItemModel: QDBusPendingCall
AMAppItemModel->>QDBusPendingCallWatcher: QDBusPendingCallWatcher(QDBusPendingCall)
QDBusPendingCallWatcher-->>AMAppItemModel: finished
AMAppItemModel->>AMAppItemModel: QDBusPendingReply<ObjectMap> reply
AMAppItemModel->>AMAppItemModel: [reply.isError()] log warning
AMAppItemModel->>AMAppItemModel: [!reply.isError()] appendRow(AppItem)
AMAppItemModel->>AMAppItemModel: setProperty(ready, true)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…pdates The AMAppItemModel was populated from a QtConcurrent worker thread, which mutated the model (appendRow) on a non-GUI thread while the main thread's queued onReferenceModelChanged() read it concurrently, causing a data race and a SIGSEGV in QStandardItemModel::data() during restart. 1. Replace QtConcurrent::run with QDBusPendingCallWatcher so the model is populated on the model's own (main) thread, eliminating the cross-thread race and stale queued rowsInserted callbacks. 2. Change m_referenceModel from a raw pointer to QPointer so it is automatically cleared when the model is destroyed. 3. Add a null check at the start of onReferenceModelChanged() to skip updates when the reference model has been destroyed. Log: Fixed a crash in dde-shell during restart caused by concurrent access to the app model. Influence: 1. Restart dde-shell repeatedly and verify no crash occurs. 2. Test app install/remove and grouping during restart. 3. Verify the launchpad app group arrangement is preserved after restart. fix: 修复重启时因并发访问应用模型导致的 dde-shell 崩溃 AMAppItemModel 此前在 QtConcurrent 工作线程中填充,在工作线程中修改 模型(appendRow),同时主线程通过队列回调 onReferenceModelChanged() 并发 读取模型,导致数据竞争,重启时在 QStandardItemModel::data() 中触发段错误。 1. 将 QtConcurrent::run 替换为 QDBusPendingCallWatcher,使模型在自身 (主)线程中填充,消除跨线程竞争和过期的 rowsInserted 队列回调。 2. 将 m_referenceModel 由裸指针改为 QPointer,模型销毁时自动置空。 3. 在 onReferenceModelChanged() 开头增加空指针检查,模型已销毁时跳过更新。 Log: 修复重启时因并发访问应用模型导致的 dde-shell 崩溃。 Influence: 1. 反复重启 dde-shell,验证不再崩溃。 2. 重启过程中测试应用的安装/卸载及分组功能。 3. 验证重启后启动器应用分组布局得以保留。 PMS: BUG-372351
f58135c to
9d3d590
Compare
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 在 amappitemmodel.cpp 中增强错误处理逻辑
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher]() {
watcher->deleteLater();
QDBusPendingReply<ObjectMap> reply = *watcher;
if (reply.isError()) {
qCWarning(appsLog) << "Failed to get managed objects:" << reply.error().message();
// 可选:发出错误信号通知UI层或触发重试机制
return;
}
auto apps = reply.value();
for (auto app = apps.cbegin(); app != apps.cend(); app++) {
auto path = app.key();
if (!path.path().isEmpty()) {
auto c = new AMAppItem(path.path(), app.value());
appendRow(c);
}
}
setProperty("ready", true);
qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();
}); |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, Ivy233 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 |
…pdates
The AMAppItemModel was populated from a QtConcurrent worker thread, which mutated the model (appendRow) on a non-GUI thread while the main thread's queued onReferenceModelChanged() read it concurrently, causing a data race and a SIGSEGV in QStandardItemModel::data() during restart.
Log: Fixed a crash in dde-shell during restart caused by concurrent access to the app model.
Influence:
fix: 修复重启时因并发访问应用模型导致的 dde-shell 崩溃
AMAppItemModel 此前在 QtConcurrent 工作线程中填充,在工作线程中修改
模型(appendRow),同时主线程通过队列回调 onReferenceModelChanged() 并发 读取模型,导致数据竞争,重启时在 QStandardItemModel::data() 中触发段错误。
Log: 修复重启时因并发访问应用模型导致的 dde-shell 崩溃。
Influence:
PMS: BUG-372351
Summary by Sourcery
Prevent dde-apps crash on restart by making app model population and group updates safe against concurrent access and destroyed models.
Bug Fixes:
Enhancements: