Repository navigation
fix: prevent cross-thread model access in notification settings - #1761
Conversation
Reviewer's GuideThe PR eliminates cross-thread model access by introducing a model-thread snapshot observer, asynchronously coalescing model changes, and delivering generation-validated cached snapshots to NotificationSetting before its consumer signals are emitted. Sequence diagram for model-thread app snapshot updatessequenceDiagram
participant Model as QAbstractItemModel
participant Observer as AppModelObserver
participant Setting as NotificationSetting
participant Consumer as NotificationSettingsConsumer
Model->>Observer: rowsInserted / rowsRemoved / modelReset / dataChanged
Observer->>Observer: QTimer::start()
Note over Observer: Zero-interval timer coalesces model changes
Observer->>Observer: appItems()
Observer-->>Setting: snapshotChanged(apps)
Setting->>Setting: onAppsChanged(current)
Setting->>Setting: Update m_appItems cache
Setting-->>Consumer: appAdded / appRemoved
Consumer->>Setting: appItems() / appItem() / appValue()
Sequence diagram for accessor replacement and stale snapshot rejectionsequenceDiagram
participant Caller
participant Setting as NotificationSetting
participant OldObserver as OldAppModelObserver
participant NewModel as NewQAbstractItemModel
participant NewObserver as NewAppModelObserver
Caller->>Setting: setAppAccessor(NewModel)
Setting->>Setting: Increment m_appAccessorGeneration
Setting->>OldObserver: Retire observer
Setting->>NewObserver: Create observer
NewObserver->>NewModel: appItems()
NewObserver-->>Setting: Initial snapshot
Setting->>Setting: Publish initial cache
OldObserver-->>Setting: Queued snapshotChanged(apps)
Setting->>Setting: Compare snapshot generation
Setting-->>OldObserver: Ignore stale snapshot
File-Level Changes
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: wjyrich 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 |
e299ca2 to
4efd130
Compare
|
/retest |
|
建议缩小这次跨线程修复的改动范围:保留 可以按下面的方式调整:
这样保留 零间隔合并刷新可以保留:应用模型初始化时会逐条插入,合并后能避免每插入一条就全量扫描。 |
4efd130 to
1f0e303
Compare
1. Add stopAppMonitoring() to NotificationSetting and NotificationManager to disconnect model signals before deletion 2. Use DirectConnection for model signal handlers so onAppsChanged runs in the model's emitting thread 3. Cache app items lazily in setAppAccessor and update cache atomically in onAppsChanged 4. Add thread assertions and make appItems() a pure cache reader 5. Call stopAppMonitoring() in NotifyServerApplet destructor before deleteLater 6. Add NotificationSetting destructor to ensure monitoring is stopped 7. Remove unused QTimer include and update copyright year Log: Fixed thread-safety issues in notification app monitoring Influence: 1. Test notification settings app list loading and display 2. Verify app install/uninstall triggers correct appAdded/appRemoved signals 3. Test notification server shutdown and restart for crashes or hangs 4. Verify app-specific notification settings persist correctly 5. Test with rapid app list changes to check for race conditions 6. Confirm no deadlocks occur during server exit fix: 修复通知应用监控中的跨线程访问问题 1. 为 NotificationSetting 和 NotificationManager 添加 stopAppMonitoring(),在删除前断开模型信号 2. 模型信号处理器使用 DirectConnection,使 onAppsChanged 在模型发射线程 中运行 3. 在 setAppAccessor 中惰性缓存应用项,并在 onAppsChanged 中原子更新缓存 4. 添加线程断言,使 appItems() 成为纯缓存读取 5. 在 NotifyServerApplet 析构函数中、deleteLater 之前调用 stopAppMonitoring() 6. 添加 NotificationSetting 析构函数以确保停止监控 7. 移除未使用的 QTimer 头文件并更新版权年份 Log: 修复通知应用监控的线程安全问题 Influence: 1. 测试通知设置应用列表的加载和显示 2. 验证应用安装/卸载是否正确触发 appAdded/appRemoved 信号 3. 测试通知服务关闭和重启,检查是否崩溃或卡死 4. 验证应用专属通知设置是否正确持久化 5. 测试应用列表快速变化以检查竞态条件 6. 确认服务退出过程中不会发生死锁 PMS: BUG-379243
1f0e303 to
bf59a3a
Compare
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Influence:
fix: 修复通知设置中跨线程访问模型的问题
Influence:
PMS: BUG-379243 BUG-379237
Summary by Sourcery
Ensure notification settings access application data through consistent, thread-safe snapshots while safely coordinating model monitoring across threads and shutdown.
Bug Fixes:
Enhancements: