Merged
fix(Fabric): destroy ComponentInstanceProvider on UI thread via custom deleter #3941
fix(Fabric): destroy ComponentInstanceProvider on UI thread via custom deleter #3941
Merged
xjerwuAdd on 4 days ago
xjerwu
xjerwuCollaborators
4 days ago

Change Type

Check the corresponding type (√), only one may be selected:

Change Scope

Change Description

  • Summary: Install a custom deleter on the ComponentInstanceProvider shared_ptr so the final delete runs on the UI (MAIN) thread — directly if already on MAIN, otherwise posted to MAIN.
  • Root cause: ComponentInstanceProvider (the preallocation delegate) can be destroyed on an ffrt worker thread when the preallocation-parallelization lambda in ComponentInstancePreallocationRequestQueue::push drops the last strong reference at the end of the lambda. This cascades into ~TextComponentInstance on a non-UI thread, where disposeTextStorage() → resetTextContentWithStyledString() → NodeApi::resetAttribute() → maybeThrow calls an ArkUI attribute API off the UI thread, gets a non-zero status, throws std::runtime_error, and escapes the implicit noexcept destructor → std::terminate() crash. The existing try/catch around processPreallocationRequest cannot intercept this (destruction happens at lambda scope exit, outside the try, and destructors are noexcept).
  • Solution: A custom deleter on the shared_ptr<ComponentInstanceProvider>: when the last strong reference is released, if already on the UI thread, delete p directly; otherwise post delete p to TaskThread::MAIN. The inner posted lambda captures taskExecutor (strong ref) so TaskExecutor stays alive until the task completes, even after the control block releases the outer strong ref. ~ComponentInstanceProvider and the component instances it owns now always run on the UI thread, so ArkUI attribute calls are made on the correct thread.
  • Compatibility: Only changes the destruction thread of ComponentInstanceProvider; no public API change; no business-logic impact.

RNOH Special Notes

Native layer change notes:

  • libhermes.so symbols unchanged; no .so impact. The change only affects where ~ComponentInstanceProvider (and thus ArkUI node cleanup via ~ArkUINode::disposeNode) runs, forcing it onto the UI thread.

Linked Issue

Linked #3594.

Testing

Checklist

likedislike
Pull Request has been successfully merged by openharmony_ci.
(Thank you for xjerwu's contribution.)
xjerwuxjerwuCollaborators
4 days ago Added label: bug
cpf-managercpf-managerCollaborators
4 days ago Added label: AI检视中
xjerwu
xjerwuCollaborators
4 days ago Comments:

start build

likedislike
openharmony_ci
openharmony_ciCollaborators
4 days ago Comments:

该提交没有关联任何Issue,请先关联一个Issue后再触发构建
The PR is not associated with any Issue, Please associate the PR with one Issue before trigger build.

likedislike
openharmony_ci
openharmony_ciCollaborators
4 days ago Comments:

感谢提交 Pull Requests!
Thanks for submitting a pull request.

likedislike
openharmony_ciopenharmony_ciCollaborators
4 days ago Added label: dco检查成功
xjerwuxjerwuCollaborators
4 days ago Modify description of pull request
cpf-managercpf-managerCollaborators
4 days ago Removed label: AI检视中
cpf-managercpf-managerCollaborators
4 days ago Added label: AI已检视
xjerwu
xjerwuCollaborators
4 days ago Comments:

start build

likedislike
openharmony_ci
openharmony_ciCollaborators
4 days ago Comments:

首次触发
门禁构建开始,包含静态检查、代码编译和测试【rnoh_main-test编译, rnoh_main测试, rnoh_main编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6afd1f1964650f998b8d98e3/runlist

likedislike
openharmony_ciopenharmony_ciCollaborators
4 days ago Added label: 编译成功
openharmony_ciopenharmony_ciCollaborators
4 days ago Added label: 静态检查成功
openharmony_ciopenharmony_ciCollaborators
4 days ago Test passed
openharmony_ci
openharmony_ciCollaborators
4 days ago Comments:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6afd1f1964650f998b8d98e3/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result test result package
1 rnoh_main success success(IGNORE) >>>
2 rnoh_main-test success NA >>>

likedislike
haozhihanghaozhihangCollaborators
3 days ago Set haozhihang as approver
haozhihanghaozhihangCollaborators
3 days ago Approval passed
saberblacksaberblackCollaborators
3 days ago Approval passed
cpf-managercpf-managerCollaborators
3 days ago Added label: AI检视复核中
cpf-managercpf-managerCollaborators
3 days ago Reset test status
cpf-manager
cpf-managerCollaborators
3 days ago Comments:

【AI-Review复核报告】

结论: ✅ 通过

复核基线: 4f3645d0 | 意见总数: 0 | 有效处置: 0 | 无效处置: 0

全部意见均已正确处置(已修复 / 有据非问题 / Issue跟踪),测试通过。

likedislike
cpf-managercpf-managerCollaborators
3 days ago Test passed
cpf-managercpf-managerCollaborators
3 days ago Removed label: AI检视复核中
cpf-managercpf-managerCollaborators
3 days ago Added label: AI检视复核通过
openharmony_ciopenharmony_ciCollaborators
3 days ago Closed associated issue
openharmony_ciopenharmony_ciCollaborators
3 days ago Merged pull request, merge node SHA: 9b76f59dd5e810444f98b0be89895ef5c630c280