Skip to content

[draft] [test] Fix for concurrent multi-attach test#5359

Draft
saxena-anurag wants to merge 14 commits into
mainfrom
user/anusa/issue_5238
Draft

[draft] [test] Fix for concurrent multi-attach test#5359
saxena-anurag wants to merge 14 commits into
mainfrom
user/anusa/issue_5238

Conversation

@saxena-anurag

@saxena-anurag saxena-anurag commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a race in test setup for native helper initialization by limiting global link cleanup to the main thread only. Closes #5238.

Problem

_native_module_helper::initialize() detached all existing BPF links unconditionally. In multi-threaded test runs, worker threads could execute this cleanup concurrently and detach links that were just created by other threads, causing intermittent/racy attach failures.

Change

In tests/libs/util/native_helper.cpp, move the link cleanup loop behind an _is_main_thread guard:

  • Set _is_main_thread before any REQUIRE calls, as before.
  • Run bpf_link_get_next_id / bpf_link_get_fd_by_id / bpf_link_detach cleanup only when is_main_thread == true.
  • Keep existing behavior for execution type handling unchanged.

This preserves cleanup semantics for the primary test thread while preventing worker threads from interfering with freshly attached links.

Testing

Existing CICD.

  • Unit tests are added.
  • Driver tests are added.

Documentation

No documentation impact.

Installation

No installer impact.

saxena-anurag and others added 14 commits June 9, 2026 17:43
Instead of preventing cleanup on worker threads (which left leftover program
state), use a static CRITICAL_SECTION to serialize link cleanup across all
threads. This prevents races where one thread detaches links while another
is attaching them, while still ensuring all threads clean up their state.

- Add _cleanup_lock static mutex to _native_module_helper
- Initialize/destroy lock via static helper object
- Wrap bpf_link cleanup sequence in EnterCriticalSection/LeaveCriticalSection

This fixes API test failures that were caused by leftover programs from
previous test runs polluting the system state.
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.

Workflow failed - regression_driver_ws2022

1 participant