[mock_tests] Fix Orch object file descriptor leak in test TearDown - #151
Conversation
Fix file descriptor leak in mock test fixtures caused by gDirectory.m_values.clear() not deleting the pointed Orch objects. Each Orch object holds real OS sockets created by mock DBConnector (socket(AF_UNIX, SOCK_DGRAM, 0)). When TearDown only clears the gDirectory map without deleting the objects, these sockets accumulate across test runs, eventually causing "Too many open files" errors for tests that run later in the sequence. The fix properly deletes all leaked Orch objects before clearing gDirectory in each test fixture's TearDown/deinitOrch: - portsorch_ut.cpp: delete FlexCounterOrch - routeorch_ut.cpp: delete MuxOrch, TunnelDecapOrch, FlexCounterOrch, FlowCounterRouteOrch - qosorch_ut.cpp: delete FlexCounterOrch - bufferorch_ut.cpp: delete FlexCounterOrch - fdborch/flush_syncd_notif_ut.cpp: delete VxlanTunnelOrch - intfsorch_ut.cpp: delete MuxOrch, TunnelDecapOrch, FlexCounterOrch, VNetOrch, VNetCfgRouteOrch, VNetRouteOrch - flowcounterrouteorch_ut.cpp: delete MuxOrch, TunnelDecapOrch, FlexCounterOrch, VNetOrch, VNetCfgRouteOrch, VNetRouteOrch - mux_rollback_ut.cpp: add BufferOrch to ut_orch_list for proper reverse-order deletion For TunnelDecapOrch (not stored in gDirectory), promote the local variable to a class member (m_tunnel_decap_orch) in 3 fixtures (routeorch_ut, intfsorch_ut, flowcounterrouteorch_ut) to enable proper cleanup. Tested: 119/119 tests PASSED with zero "Too many open files" errors.
There was a problem hiding this comment.
Pull request overview
This PR fixes file descriptor leaks in mock test fixtures that were causing "Too many open files" errors when running the full test suite sequentially. The root cause is that gDirectory.m_values.clear() only removes map entries without deleting the pointed-to Orch objects, which hold file descriptors through DBConnector instances.
Changes:
- Added explicit deletion of Orch objects from gDirectory before calling
gDirectory.m_values.clear()in test TearDown methods - Promoted
TunnelDecapOrchlocal variables to test fixture member variables in three test files to enable proper cleanup - Added missing
gBufferOrchtout_orch_listin mux_rollback_ut.cpp for reverse-order deletion
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/mock_tests/routeorch_ut.cpp | Added m_tunnel_decap_orch member and deletion of MuxOrch, TunnelDecapOrch, FlexCounterOrch, FlowCounterRouteOrch before gDirectory.clear() |
| tests/mock_tests/qosorch_ut.cpp | Added deletion of FlexCounterOrch before gDirectory.clear() |
| tests/mock_tests/portsorch_ut.cpp | Added deletion of FlexCounterOrch before gDirectory.clear() |
| tests/mock_tests/mux_rollback_ut.cpp | Added gBufferOrch to ut_orch_list for proper cleanup |
| tests/mock_tests/intfsorch_ut.cpp | Added m_tunnel_decap_orch member and deletion of MuxOrch, TunnelDecapOrch, FlexCounterOrch, VNetOrch, VNetCfgRouteOrch, VNetRouteOrch before gDirectory.clear() |
| tests/mock_tests/flowcounterrouteorch_ut.cpp | Added m_tunnel_decap_orch member and deletion of MuxOrch, TunnelDecapOrch, FlexCounterOrch, VNetOrch, VNetCfgRouteOrch, VNetRouteOrch before gDirectory.clear() |
| tests/mock_tests/fdborch/flush_syncd_notif_ut.cpp | Added deletion of VxlanTunnelOrch before gDirectory.clear() |
| tests/mock_tests/bufferorch_ut.cpp | Added deletion of FlexCounterOrch before gDirectory.clear() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
File Descriptor Leak Fix - Test ReportDate: 2026-02-26 Executive SummaryThis report provides empirical evidence that commit Test Methodology
Results Summary
Key Metrics
FD Usage Timeline ComparisonBefore Fix (high ulimit) - FDs grow monotonically, never releasedAfter Fix (high ulimit) - FDs rise then stabilize at lower levelDetailed Failure Analysis (Before Fix, ulimit -n = 800)All 29 failures are caused by fd exhaustion during test
Pattern: Tests that run after the fd count exceeds the 800 limit fail. Earlier test suites Root Cause VerificationThe fd leak is caused by Orch objects created with // mock_dbconnector.cpp
DBConnector::DBConnector(...) {
m_conn = (redisContext*)calloc(1, sizeof(redisContext));
m_conn->fd = socket(AF_UNIX, SOCK_DGRAM, 0); // Real fd!
}Before fix: Steady-State FD Comparison
The 595 fd difference represents the accumulated leaked sockets from ~100 test SetUp/TearDown Files Modified (8 files)
ConclusionThe fix demonstrably:
|
[mock_tests] Fix Orch object file descriptor leak in test TearDown
Description
Fix file descriptor leaks in mock test fixtures that cause
"Too many open files"errors when running the full test suite sequentially.Root Cause
Each mock test
SetUp()creates multiple Orch objects vianewand stores them ingDirectoryusinggDirectory.set(). However, inTearDown():Directory::m_valuesisstd::unordered_map<std::string, Orch*>. Callingclear()removes map entries but never invokes destructors on the pointed-to objects.Since
mock_dbconnector.cppcreates real OS sockets (socket(AF_UNIX, SOCK_DGRAM, 0)) for eachDBConnector, and each Orch object internally holds multipleDBConnector/RedisPipeline/Tableinstances, the leaked sockets accumulate across test runs until the process hits theulimit -nlimit.Fix
Before
gDirectory.m_values.clear(), retrieve anddeleteall Orch objects stored in gDirectory that are not otherwise cleaned up via global pointer deletion:For
TunnelDecapOrch(not stored in gDirectory, passed as local variable toMuxOrchconstructor), promote to a class member (m_tunnel_decap_orch) to enable proper cleanup.For
mux_rollback_ut.cpp(usesut_orch_listfor reverse-order deletion), add the missinggBufferOrchtout_orch_list.Changed Files (8 files, all under
tests/mock_tests/)portsorch_ut.cppFlexCounterOrchrouteorch_ut.cppMuxOrch,TunnelDecapOrch(member),FlexCounterOrch,FlowCounterRouteOrchqosorch_ut.cppFlexCounterOrchbufferorch_ut.cppFlexCounterOrchfdborch/flush_syncd_notif_ut.cppVxlanTunnelOrchintfsorch_ut.cppMuxOrch,TunnelDecapOrch(member),FlexCounterOrch,VNetOrch,VNetCfgRouteOrch,VNetRouteOrchflowcounterrouteorch_ut.cppMuxOrch,TunnelDecapOrch(member),FlexCounterOrch,VNetOrch,VNetCfgRouteOrch,VNetRouteOrchmux_rollback_ut.cppBufferOrch(added tout_orch_list)Test Results
Risk Assessment
tests/mock_tests/), no production code changes