Skip to content

Add optional ASAN test-leak injection gated by a config file - #4813

Open
judsonwilson-nvidia wants to merge 2 commits into
sonic-net:masterfrom
judsonwilson-nvidia:asan_leak_injection
Open

Add optional ASAN test-leak injection gated by a config file#4813
judsonwilson-nvidia wants to merge 2 commits into
sonic-net:masterfrom
judsonwilson-nvidia:asan_leak_injection

Conversation

@judsonwilson-nvidia

@judsonwilson-nvidia judsonwilson-nvidia commented Aug 3, 2026

Copy link
Copy Markdown

Why I did it

ASAN builds need a way to confirm that LSan and the SIGTERM leak check are
actually firing. Without a controlled leak, a silent miss looks the same as a
clean exit. A matching change is in sonic-sairedis (syncd/Asan.cpp).
sonic-net/sonic-sairedis#2025

This can be used to help detect issues like the following where ASAN is not
configured correctly:

sonic-net/sonic-buildimage#28279

Work item tracking
  • Microsoft ADO (number only): N/A

How I did it

  • In lib/asan.cpp, when /etc/sonic/inject_asan_test_leak_enabled exists at
    startup, inject a fixed-size intentional leak so the SIGTERM LSan check has
    something to report.
  • Run the injector on a short-lived helper thread so the allocation stays
    unreachable after join (avoids ASAN fake-stack false reachability at -O2).
  • Leave the existing SIGTERM handler and LSan suppressions unchanged.
  • Mirrors the upcoming sonic-sairedis change in syncd/Asan.cpp.

How to verify it

  1. Create /etc/sonic/inject_asan_test_leak_enabled.
  2. Restart the daemon once if needed (e.g. config reload) so it starts with
    leak injection enabled.
  3. Run config reload or reboot to send SIGTERM.
  4. Confirm ASAN report files appear under /var/log/asan/.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305
  • 202311
  • 202405
  • 202411

Tested branch (Please provide the tested image version)

  • master before 202611

Description for the changelog

Add optional ASAN test-leak injection gated by a config file for testing ASAN functionality.

A picture of a cute animal (not mandatory but encouraged)

If /etc/sonic/inject_asan_test_leak_enabled exists, swss daemons inject a known
leak, so that when sent SIGTERM the leak detector will emit an ASAN report.
This can be used to verify that the ASAN build and the leak check in the
signal handler are working as intended.

This matches a similar addition being made in sonic-sairedis.

How to verify it:
1. Create /etc/sonic/inject_asan_test_leak_enabled.
2. Restart the daemon once if necessary (e.g. `config reload`) so it starts
   with leak injection enabled.
3. Run `config reload` or reboot to send SIGTERM to the daemon.
4. After it exits, daemons that are working correctly will produce ASAN
   report files in /var/log/asan/.

Signed-off-by: Judson Wilson <judsonw@nvidia.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

dgsudharsan
dgsudharsan previously approved these changes Aug 3, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi @sonic-net/sonic-swss-maintainer, this approved PR has workflow run(s) waiting for approval. Please help review. Thanks!

---Powered by SONiC BuildBot

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Judson Wilson <judsonw@nvidia.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

3 participants