[agent] Use std::_Exit() to avoid EventBase double-drive on HwAgent exit - #1525
[agent] Use std::_Exit() to avoid EventBase double-drive on HwAgent exit#1525AnantKishorSharma wants to merge 1 commit into
Conversation
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
This is already being fixed by #1492. The change there makes sure destructors are executed and it also targets other exit paths (disconnects, s/w agent, etc.). |
Summary
SplitHwAgentSignalHandler::signalReceived()performs a graceful shutdown (unregister callbacks, stop oper-delta sync, stop services,gracefulExit()which writes warm-boot state) and then callsexit(0).exit(0)runs global/atexit destructors. During a warm-boot shutdown those destructors can re-enter and drive the still-live thriftfolly::EventBase— the onehwAgentMain()is driving inserver->serve()on the main thread — from the signal-handler thread. Two threads then drive the same EventBase, tripping folly's check inEventBase.cpp:The process aborts before the oper-delta ack is sent, so the peer SW agent waits out
oper_delta_ack_timeout(600s) and the warm-boot iteration fails on timeout. Cold-boot exit takes thehwAgent_.reset()branch and does not hit this, which is why only warm boot is affected.Fix
Replace
exit(0)withstd::_Exit(0). All required graceful cleanup (warm-boot state write viagracefulExit(), service/syncer shutdown) has already completed earlier in the handler, so the global/atexit destructors add nothing here; skipping them avoids the second EventBase drive and the resulting abort. This mirrors the existingstd::_Exit(rc)usage infboss/agent/hw/test/Main.cpp.Test Plan
gracefulExit()persists warm-boot state before the exit call, sostd::_Exit()loses no state.hwAgent_.reset()path) and theagent_exit_delay_sdelay path are unchanged.Runtime workaround, not a fix:
agent_exit_delay_sFor anyone who can't pick up this patch yet, the same warm-boot abort can be mitigated at runtime without a rebuild via the existing
agent_exit_delay_sgflag (AgentFeatures.cpp). It sleeps right before theexit(0)in this handler — aftergracefulExit()has already persisted warm-boot state — giving the main thread'sserver->serve()loop time to unwind before the atexit/global destructors run. It can be set via the agent config'sdefaultCommandLineArgs(both agents read it), e.g."agent_exit_delay_s": "5"(bump to"10"if needed).Caveats:
std::_Exit()in this PR is the deterministic fix.