Open
[BUG] orchestrator 将遗留 netns 标记误判为外部 namespace,导致网络槽位无法复用 #3
jokp_zAdd on  Aug 29
jokp_z
jokp_z
Aug 29 Create

【缺陷描述】:请补充详细的缺陷问题现象描述

KASandbox 使用本地网络槽位时,orchestrator 启动会扫描 /var/run/netns。

当前实现会将该目录下除 host 和目录之外的所有条目直接记录为 foreign namespace,但异常退出或清理不完整后,/var/run/netns/ns-N 可能只是遗留的普通 mountpoint/marker 文件,已经不是有效的 network namespace 挂载。

服务重启后,这类遗留文件仍会被识别为外部 namespace,对应网络槽位不再参与分配。遗留条目持续积累后,可用网络槽位逐渐减少,最终可能导致 Sandbox 创建失败。

一、缺陷信息

【缺陷模块】

packages/orchestrator/internal/sandbox/network/storage_local.go

【触发条件】

  1. 使用 local network storage
  2. Sandbox 网络 namespace 删除不完整
  3. orchestrator/template-manager 异常退出
  4. /var/run/netns 下遗留 ns-N 普通文件或失效 mountpoint
  5. orchestrator/template-manager 随后重新启动

【问题概率】

单次异常清理不一定发生,但问题具有累积性。每个遗留的 ns-N 都可能占用一个网络槽位,长期运行、频繁创建和销毁 Sandbox 时风险逐渐增加。

【影响】

  1. 对应网络槽位无法重新使用
  2. 节点可用网络槽位逐渐减少
  3. ip netns list 反复输出 “Error: Peer netns reference is invalid.”
  4. 严重时 Sandbox 创建失败并出现 “failed to acquire IP slot: timeout”

【初步分析】

当前 getForeignNamespaces() 只根据 /var/run/netns 下的目录项名称判断是否为 foreign namespace。

isNamespaceAvailable() 也只通过 os.Stat() 判断路径是否存在,无法区分:

  1. 有效的 nsfs network namespace 挂载
  2. 异常退出后遗留的普通文件或失效 mountpoint

因此,KASandbox 自己管理的 stale ns-N 会被误判为外部程序创建的 namespace,并在当前进程生命周期内永久跳过。

【缺陷所属的os版本】

openEuler 24.03 (LTS-SP3)

【内核版本】

【缺陷所属软件及版本号】

KASandbox android 分支

【环境信息】

硬件信息

  • 架构:aarch64
  • 部署方式:ARM 裸金属服务器

软件信息

  • 操作系统:openEuler 24.03 (LTS-SP3)
  • KASandbox:android 分支
  • template-manager 通过 DaemonSet 部署
  • orchestrator 与 template-manager 服务运行在 template-manager 容器中
  • 使用 local network storage
  • network namespace 目录:/var/run/netns

网络信息

  • 每个节点在宿主机上创建和管理 Sandbox network namespace
  • KASandbox 管理的 namespace 使用 ns-N 命名
  • 问题发生在宿主机本地 namespace 状态扫描和槽位分配阶段
  • 与具体业务网段或外部网络地址无关

【问题复现步骤】

【实际结果】

【期望结果】

【其他相关附件信息】

【缺陷详情及分析指导参考链接】

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
Aug 29 Assign weibaohui、yangzhao_kl、jimmieme、duguhaotian、wonleing、zmr_2020、gaodaweiky、lu-wei-army、zhaoyifan28、jokp_z as responsible person
openeuler-ci-botopeneuler-ci-botCollaborators
Aug 29 Added label: sig/sig-CloudNative
openeuler-ci-bot
openeuler-ci-botCollaborators
Aug 29 Comments:

Welcome To openEuler Community

Hey @jokp_z , 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. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

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: @feijianqiang, @zhourenjianz .

likedislike
yaqiangchen
yaqiangchen
1 day ago Comments:

复核了当前 master 的实现,这个缺陷的根因看起来已经修掉了,建议提报人验证后关闭(我在本仓库无关闭权限):

现在的 packages/orchestrator/internal/sandbox/network/storage_local.go 里,scanNamespaces() 不再把所有非 host/非目录条目一律记为 foreign,而是分三类处理:

  1. 非本组件命名(不是 ns-N)→ 仍记为 foreign(这是正确的,可能是别的工具的 netns);
  2. 本组件命名但无效(isValidNetNSMount 判断)→ 直接清理,不标记为 foreign;
  3. 本组件命名且有效 → 再按归属标记 slot_owner 判定:
    • 没有标记 / 标记 owner 仍存活 / owner 是自己 → foreign;
    • 标记的 owner 进程已不存在 → 加入 orphaned 回收列表。

关键点正是 issue 里指出的那条链路:isValidNetNSMount()(storage_local.go:226)用设备号区分「真实 netns 挂载(nsfs)」与「tmpfs 上的普通残留文件」——st.Dev != parentSt.Dev,所以异常退出留下的普通 mountpoint/marker 不会再被当成 foreign namespace,槽位也不会持续泄漏。

另外新增了 slot_owner.go 的归属标记机制,用来区分「别的实例在用」和「上一代遗留」。

建议:提报人用原来能复现的场景(异常退出后重启 orchestrator,检查 /var/run/netns/ns-N 是否被回收、槽位是否恢复可用)回归一次;通过后请维护者关闭本单。如果仍有残留不被回收,麻烦附上 ls -la /var/run/netns、findmnt /var/run/netns/* 和 orchestrator 启动日志。

likedislike