Skip to content

[Cisco] Fix SAI hash detach during load balancer removal - #1898

Open
selekkala wants to merge 1 commit into
meta:mainfrom
selekkala:fix/sai-hash-detach
Open

selekkala wants to merge 1 commit into
meta:mainfrom
selekkala:fix/sai-hash-detach

Conversation

@selekkala

@selekkala selekkala commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Pre-submission checklist

  • git diff --check
  • pre-commit run

Summary

Removing an FBOSS load balancer can leave its SAI hash object attached to the switch on ASICs that do not support SAI_HASH_FIELDS_CLEAR_BEFORE_SET. The subsequent SaiHash release then removes an object that SAI still considers referenced, which can fail with OBJECT_IN_USE and crash the SW agent during load-balancer removal.

This PR detaches ECMP and LAG hash objects unconditionally before releasing their owning references and adds a regression test for the unsupported-feature case.

Root Cause

SaiSwitchManager::removeLoadBalancer() used resetLoadBalancer() to clear the switch hash attributes. resetLoadBalancer() is intentionally gated by HwAsic::Feature::SAI_HASH_FIELDS_CLEAR_BEFORE_SET, because it was introduced as a workaround for replacing hash fields on selected SAI implementations.

On GR2, that feature is unsupported. The switch therefore continued to reference the old hash object while ecmpV[46]Hash_ or lagV[46]Hash_ was reset. SAI object lifetime ordering was violated: the hash object was released before the switch reference was cleared.

Fix

  • Add an unconditional detachLoadBalancer<HashAttrT>() helper that writes SAI_NULL_OBJECT_ID to the switch hash attribute.
  • Use it for ECMP and LAG IPv4/IPv6 hash attributes in removeLoadBalancer() before resetting the corresponding shared_ptr.
  • Keep resetLoadBalancer() feature-gated for its original hash-field replacement workaround; this change does not alter add/update programming behavior.

Test Plan

  • Added SaiHashDetachTest.removeLoadBalancerDetachesHashesBeforeRelease.
    • Uses a fake ASIC with SAI_HASH_FIELDS_CLEAR_BEFORE_SET disabled.
    • Programs and removes both ECMP and LAG hashes.
    • Verifies the switch attributes are cleared and the fake SAI hash objects are released.
  • git diff --check passed.
  • Existing g200 FBOSS image build passed in the associated buildimage workspace.
  • Live R1 reproduction using the affected load-balancer configuration completed with both agents active, zero restarts, no coredump, and no crash/fatal/segmentation-fault messages after the SW-agent restart.

The focused Buck2 test could not be executed in this checkout because its generated external-cell configuration is not present; the test is included for mainline CI.

Signed-off-by: Seshagirirao Lekkala <selekkal@cisco.com>
@selekkala
selekkala requested a review from a team as a code owner November 2, 2026 19:17
@meta-cla meta-cla Bot added the CLA Signed label Nov 2, 2026
@selekkala selekkala changed the title Fix SAI hash detach during load balancer removal [Cisco] Fix SAI hash detach during load balancer removal Nov 2, 2026
@vasantspatil vasantspatil self-assigned this Nov 4, 2026
@vasantspatil
vasantspatil self-requested a review November 4, 2026 23:38

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants