Repository navigation
fix: stop backend write thread before teardown in ~Settings - #629
Merged
lzwind merged 1 commit intoSep 29, 2026
Merged
Conversation
DSettings::setBackend() moves the backend to a dedicated write thread and only DSettings::destroyed quits and waits for it. ~Settings() deleted the backend first while never destroying DSettings, so the main thread could free the backend (and its QSettings) while the write thread was still running doSetOption, causing a use-after-free SIGSEGV (exit 139) in CI test_settings, reliably reproduced by the BUG102351 case in full-suite runs. Destroy DSettings before deleting m_backend so the write thread is stopped first; this also fixes the DSettings instance leak. Log: 修复 Settings 析构与 backend 写线程竞态导致的段错误(CI UT 退出码 139) Influence: Settings 析构顺序调整,无接口变化;顺带修复 DSettings 实例泄漏
Reviewer's guide (collapsed on small PRs)Reviewer's Guide修复 Settings 析构期间 backend 写线程仍在异步访问已销毁 QSettings 的竞态:析构时先释放 DSettings 以停止并等待写线程,再释放 backend,并消除 DSettings 泄漏;全量 test_settings 验证由稳定崩溃恢复为连续通过。 Sequence diagram for safe Settings teardownsequenceDiagram
participant Settings
participant DSettings
participant WriteThread
participant Backend
participant QSettings
Settings->>DSettings: delete settings
DSettings->>WriteThread: destroyed: quit()
DSettings->>WriteThread: wait()
WriteThread-->>DSettings: stopped
Settings->>Backend: delete m_backend
Backend->>QSettings: destroy safely
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
lzwind
approved these changes
Sep 29, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
CI UT 任务中
test_settings套件段错误(exit 139,SIGSEGV),gtest XML 报告未写出,套件内 66 个用例整体丢失:根因
DSettings::setBackend()会将 backendmoveToThread到专门的写线程,doSetOption/doSync经队列在该线程异步执行(dtkcore 源码确认);DSettings::destroyed信号会quit()+wait()该写线程;~Settings()只delete m_backend(backend 的线程亲和在写线程上),且成员settings(DSettings*)从不析构 → 写线程永不停止,主线程销毁 backend 及其 QSettings 时与写线程在途的doSetOption竞态。core dump 堆栈(崩溃线程为 DTK 写线程,非主线程):
修复
~Settings()中先delete settings(触发DSettings::destroyed→ 写线程 quit+wait 停稳),再delete m_backend;同时修复 DSettings 实例泄漏。验证
复刻 CI 运行环境(cwd=build、ASAN_OPTIONS、--gtest_output=xml、全量 66 用例):
QMutex: destroying locked mutex单跑 BUG102351 用例不触发(竞态依赖前序用例留下的在途写事件),需全量套件复现。
Summary by Sourcery
Stop the settings backend write thread before tearing down the backend to make destruction safe.
Bug Fixes:
Enhancements: