Skip to content

fix(agent): prevent panic when controller_ips is empty in remaining l… - #11947

Open
YanLongDai wants to merge 1 commit into
deepflowio:mainfrom
YanLongDai:fix/controller-ips-bounds-check-remaining
Open

YanLongDai wants to merge 1 commit into
deepflowio:mainfrom
YanLongDai:fix/controller-ips-bounds-check-remaining

Conversation

@YanLongDai

@YanLongDai YanLongDai commented Nov 3, 2026 •

Copy link
Copy Markdown

This PR is for:

  • Agent

Fixes controller_ips[0] index out of bounds panic in remaining locations

Steps to reproduce the bug

This PR fixes the same controller_ips[0] index out of bounds issue in the remaining 3 locations in agent/src/trident.rs, following the same approach as PR #11929.

  1. Deploy DeepFlow Agent v7.2.2 on KylinOS V10 (aarch64)
  2. Create config file without controller-ips field:
    controller-port: 30035
    log-file: /var/log/deepflow-agent/deepflow-agent.log
    log-level: info
    agent-mode: standalone
  3. Start agent: systemctl start deepflow-agent
  4. Agent crashes immediately with signal 6 (SIGABRT)

When the agent starts without controller-ips configured, it may panic at different locations depending on the execution path:

  • Line 720: Trident::run() function (eBPF initialization path)
  • Line 848: Synchronizer::new() call (config sync path)
  • Line 971: SidecarPoller::new() call (sidecar mode path)

Stack trace example (Line 720):

Stack trace of thread:
#0  raise (libc.so.6)
#1  abort (libc.so.6)
#2-#10 Rust panic chain
#11 deepflow_agent::trident::Trident::run (deepflow-agent)  ← PANIC HERE
#12 deepflow_agent::main (deepflow-agent)

Test environment:

OS: KylinOS V10 (aarch64)
Kernel: 4.19.90-89.37.v2401.ky10.aarch64
Architecture: ARM64 (aarch64)
DeepFlow Agent: v7.2.2 (native community version)

Verification:

Program Version Config Result
Native (70M) Minimal (no controller-ips) ❌ Crash
Native (70M) With controller-ips ✅ Normal

Conclusion: This is a bug in the native DeepFlow code, verified on community version v7.2.2.

Changes to fix the bug

Location 1: Trident::run() - Line 720

Before:

let controller_ip: IpAddr = config_handler.static_config.controller_ips[0].parse()?;

After:

let controller_ip: IpAddr = config_handler
    .static_config
    .controller_ips
    .first()
    .ok_or_else(|| {
        anyhow::anyhow!(
            "controller_ips is empty, please configure controller-ips in standalone mode"
        )
    })?
    .parse()?;

Location 2: Synchronizer::new() - Line 848

Before:

config_handler.static_config.controller_ips[0].clone(),

After:

config_handler
    .static_config
    .controller_ips
    .first()
    .ok_or_else(|| {
        anyhow::anyhow!(
            "controller_ips is empty, please configure controller-ips in standalone mode"
        )
    })?
    .clone(),

Location 3: SidecarPoller::new() - Line 971

Before:

config_handler.static_config.controller_ips[0].parse()?,

After:

config_handler
    .static_config
    .controller_ips
    .first()
    .ok_or_else(|| {
        anyhow::anyhow!(
            "controller_ips is empty, please configure controller-ips in standalone mode"
        )
    })?
    .parse()?,

Affected branches

  • main

Related PR

Checklist

  • Verified the fix on KylinOS V10 (aarch64) with DeepFlow Agent v7.2.2
  • Tested with both minimal and full config formats
  • No breaking changes - maintains backward compatibility
  • Same fix pattern as PR fix(agent): prevent panic when controller_ips is empty in Trident::start #11929
  • Added unit test to verify the fix.
  • Verified eBPF program runs successfully on linux 4.14.x.
  • Verified eBPF program runs successfully on linux 4.19.x.
  • Verified eBPF program runs successfully on linux 5.2.x.

Note: The eBPF verification items are not applicable for this fix as it only modifies configuration parsing logic, not eBPF programs.


Signed-off-by: Dai Yanlong daiyanlong@kylinos.cn

cc @lzf575 @rvql Please review this fix. Thanks!

…ocations

- Replace config.controller_ips[0] with config.controller_ips.first() in Trident::run() function (line 720)
- Replace config.controller_ips[0] with config.controller_ips.first() in Synchronizer::new() call (line 848)
- Replace config.controller_ips[0] with config.controller_ips.first() in SidecarPoller::new() call (line 971)
- Add proper error handling with clear error message
- Prevents panic when controller_ips Vec is empty in standalone mode

Fixes: Agent crash with signal 6 (SIGABRT) at trident.rs:720, 848, 971

Signed-off-by: Dai Yanlong <daiyanlong@kylinos.cn>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant