[orchagent]: _exit() on graceful shutdown to avoid destructor-chain memory corruption#4755
Closed
theasianpianist with Copilot wants to merge 1 commit into
Closed
[orchagent]: _exit() on graceful shutdown to avoid destructor-chain memory corruption#4755theasianpianist with Copilot wants to merge 1 commit into
theasianpianist with Copilot wants to merge 1 commit into
Conversation
Collaborator
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Copilot
AI
changed the title
[WIP] Fix orchagent crash in jemalloc during graceful shutdown
[orchagent]: _exit() on graceful shutdown to avoid destructor-chain memory corruption
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On SIGTERM/SIGINT,
OrchDaemon::start()returns andmain()falls through toreturn 0, running the full~OrchDaemondestructor chain. This is unsafe:FlexCounterManagerdestruction makes blocking SAI calls through sairedis's ZMQ channel while libzmq I/O threads are still alive, and orchs torn down earlier in the reverse-order loop have already freed buffers those threads still reference — corrupting the heap and causing intermittent jemalloc crashes.Changes
orchagent/orchdaemon.cpp— addsexit_if_graceful_shutdown_requested(): drains the async swss recorder (setAsync(false)joins the worker and flushes pending records), then calls_exit(0)to bypass the destructor chain entirelyorchagent/orchdaemon.h— declares the function with_exitas the default; accepts an injectableexit_fnfor unit testsorchagent/main.cpp— callsexit_if_graceful_shutdown_requested()immediately afterorchDaemon->start()returns on the graceful pathtests/mock_tests/orchdaemon_ut.cpp— unit tests covering the no-shutdown no-op and the drain+exit path