alibaba / alibaba/arthas

k8s 临时 debug 容器无法 attach 应用容器中的 Java 进程(跨 mount namespace)

Open
#3,246 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
37.5k
Forks
7.6k
Avg merge
1d 22h
Merged PRs (30d)
4

Description

## 问题描述
使用 `kubectl debug` 的临时容器(ephemeral container)调试应用容器中的 Java 进程时,`as.sh` / `arthas-boot` attach 失败。

## 复现环境
- 应用容器:普通用户启动的 Java 进程
- debug 容器:root,与应用容器共享 pid namespace,但 mount namespace 相互独立
- 执行 `java -jar arthas-boot.jar 1`

## 现象(依次出现)
1. `com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /tmp/.java_pid1`
2. `com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute`
3. attach 显示成功,但 `arthas-client connect 127.0.0.1 3658` 报 `Connection refused`

## 原因分析
临时容器与应用容器共享 pid namespace 但 mount namespace 独立,而 JDK 的 attach 机制默认双方在同一文件系统:
- attach socket 建在目标容器自己的 tmpdir,发起方看不到;
- `loadAgent` 让目标 JVM 打开的 agent/core jar 路径在目标侧不存在(跨 UID 时目标进程也无权读取发起方的 `/proc//root`);
- 即使递过去 agent/core 两个 jar,`ArthasBootstrap` 启动还需从 arthas home 读取 `arthas-spy.jar`(注入 bootstrap classloader,缺失即抛异常)等资源,资源不全导致 bind 失败,而 `AgentBootstrap` 会吞掉该异常,于是 `loadAgent`“成功”但 telnet 端口根本没监听。

## 期望
支持从 k8s 临时 debug 容器直接 attach 应用容器中的 Java 进程(已提交 PR 解决)。

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with `java -jar arthas-boot.jar 1` from a Kubernetes ephemeral container, then trace the attach flow through `as.sh`, `ArthasBootstrap`, and `AgentBootstrap`. Verify that the target JVM can access the attach socket and all required resources, including `arthas-spy.jar`; done means Arthas attaches successfully and `arthas-client connect 127.0.0.1 3658` succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kubernetes
Domain
devops, devtools, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.