Pull Request已成功合入, 合并人@openeuler-ci-bot
(感谢 dengchi 的贡献)变更摘要
本 PR 主要修复了当 virtiofsd 进程异常退出时,沙箱未被及时销毁的问题。核心做法是在 internal/volume/types.go 的 Device 结构体中新增运行时专用的 Exited 退出信号通道(通过 json:"-" 排除持久化),由 internal/volume/virtiofs.go 中的 watchVirtiofs 监听 exec.Cmd.Wait() 并在进程退出时关闭该通道;同时调整 Cleanup 逻辑,使其在销毁前等待 virtiofsd 进程真正退出并设置超时。internal/sandbox/manager.go 的 trackSandbox 则通过 waitForSandboxExit 同时监听 VMM 退出和 virtiofsd 退出,任一触发即执行沙箱清理。
主要改动
- 新增
Device.Exited退出信号通道:在internal/volume/types.go中为Device增加Exited <-chan struct{}字段并使用json:"-"标记,用于在运行时传递virtiofsd进程退出事件且不参与持久化。 - 新增
watchVirtiofs监听进程退出:在internal/volume/virtiofs.go中新增watchVirtiofs(cmd *exec.Cmd) <-chan struct{},通过后台cmd.Wait()并在结束后关闭通道;Prepare成功时将该通道写入Device.Exited。 - 调整
Prepare的失败清理路径:当waitUnixSocket失败时,改为在Kill后等待exited通道(仅当 kill 成功或返回unix.ESRCH/os.ErrProcessDone时),避免进程尚未退出就继续清理。 - 改造
Cleanup等待进程真正退出:将procs.LoadAndDelete改为Load,在Kill后通过devices[0].Exited等待进程退出,并引入processExitTimeout = 5 * time.Second超时;同时增加对cmd.Process == nil和缺失退出信号的错误处理。 - 沙箱管理器监听
virtiofsd退出:internal/sandbox/manager.go的Create捕获volumeDevices[0].Exited并传入trackSandbox;新增waitForSandboxExit(vmmExit, virtiofsExit),在 VMM 退出或virtiofsd退出任一事件发生时触发handleSandboxExit,从而销毁沙箱。


Welcome To openEuler Community
Hey @dcrlike , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.
Contact Guide
If you have any questions, please contact the SIG: sig-CloudNative ,
and any of the maintainers: @duguhaotian, @gaodaweiky, @jimmieme, @lu-wei-army, @weibaohui, @wonleing, @yangzhao_kl, @zhaoyifan28, @zmr_2020 ,
and any of the committers: @Yekelu .


Label Command Feedback
- Thanks for your review, your opinion is very important to us. The maintainers will consider your advice carefully.
- The label(s) lgtm permission is outside.
- Thanks for your review, your opinion is very important to us. The maintainers will consider your advice carefully.
- The label(s) approved permission is outside.


/lgtm
/approve


fix(volume): destroy sandbox when virtiofsd exits