Skip to content

libteam: Fix teamsyncd fd corruption during teamd -r#28618

Open
markx-arista wants to merge 1 commit into
sonic-net:masterfrom
markx-arista:fix-libteam-event-fd-init-and-free
Open

libteam: Fix teamsyncd fd corruption during teamd -r#28618
markx-arista wants to merge 1 commit into
sonic-net:masterfrom
markx-arista:fix-libteam-event-fd-init-and-free

Conversation

@markx-arista

@markx-arista markx-arista commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Why I did it

process_monitoring/test_critical_process_monitoring.py has been flaky on t1 topos with portchannels and Arista-7060X6-64PE-B-P32O64 had 100% failure rate on t1-f2-d10u8 since sonic-net/sonic-swss#3984 merged.

After SIGKILL + config reload, some PortChannels have members "not synced" (S* in show int portchannel). APP_LAG_MEMBER_TABLE is empty for affected LAGs, so orchagent never programs members in the ASIC. BGP sessions on these LAGs stay permanently down.

sonic-net/sonic-swss#3984 is not the root cause, but it changed timing and exposed the issue.

Work item tracking
  • Microsoft ADO (number only):

How I did it

team_handle is allocated with myzalloc which zeroes all fields, setting event_fd to 0. If team_init fails before reaching team_init_event_fd (e.g. port_list_init returns EADDRNOTAVAIL during teamd -r restart), event_fd remains 0. team_free then calls close(0), closing stdin.

nl_cli.sock is the only socket connected during team_alloc. After stdin is closed, each subsequent team_alloc gets nl_cli.sock on fd 0 (lowest available). Each subsequent failed team_free repeats close(event_fd=0), which closes whatever currently holds fd 0 — including a previously successful TeamPortSync's nl_cli.sock. This cascading corruption causes NLE_BAD_SOCK (-3) and NLE_SEQ_MISMATCH (-16) on affected handles, preventing team_ifindex2ifname from resolving member ports.

Fix by initializing event_fd to -1 in team_alloc and guarding the close in team_free.

How to verify it

Run process_monitoring/test_critical_process_monitoring.py on t1 topos with portchannels

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

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608

Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:

Tested branch

  • master
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608
  • N/A

Test result

On 202511, process_monitoring/test_critical_process_monitoring.py passed with Arista-7060X6-64PE-B-P32O64 passed on t1-f2-d10u

Description for the changelog

Initialize event_fd to -1 in team_alloc and guarding the close in team_free

Link to config_db schema for YANG module changes

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

…t_fd

team_handle is allocated with myzalloc which zeroes all fields, setting
event_fd to 0. If team_init fails before reaching team_init_event_fd
(e.g. port_list_init returns EADDRNOTAVAIL during teamd -r restart),
event_fd remains 0. team_free then calls close(0), closing stdin.

nl_cli.sock is the only socket connected during team_alloc. After stdin
is closed, each subsequent team_alloc gets nl_cli.sock on fd 0 (lowest
available). Each subsequent failed team_free repeats close(event_fd=0),
which closes whatever currently holds fd 0 — including a previously
successful TeamPortSync's nl_cli.sock. This cascading corruption causes
NLE_BAD_SOCK (-3) and NLE_SEQ_MISMATCH (-16) on affected handles,
preventing team_ifindex2ifname from resolving member ports.

Fix by initializing event_fd to -1 in team_alloc and guarding the close
in team_free.

Signed-off-by: markxiao <markxiao@arista.com>
@markx-arista
markx-arista requested a review from lguohan as a code owner July 24, 2026 19:05
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@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).

@markx-arista markx-arista changed the title libteam: Fix libteam fd corruption during teamd -r libteam: Fix teamsyncd fd corruption during teamd -r Jul 24, 2026
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.

2 participants