feat: onCancelRequested() sync hook + ABI version guard for RecoveryBehavior plugins
- RecoveryBehavior::cancel() now calls a new virtual onCancelRequested() synchronously, from whichever thread calls cancel(). Documents onCancel() as effectively dead in move_base2: it only ran on the next update() tick, and CANCELLING forces tick_recovery=false, so that tick never came. Every existing behavior's onCancel() was unreachable code. Velocity-only behaviors (wait/rotate/back_up/clear_costmap) still stop correctly via the arbiter zeroing cmd_vel; this only matters for a behavior that owns a long-running operation of its own (see Test/sbpl_recovery, separate commit). - recovery_abi.h (new) + RECOVERY_CORE_EXPORT_BEHAVIOR(factory, symbol) macro: exports an extra <symbol>_abi version symbol alongside the existing BOOST_DLL_ALIAS factory. recovery_registry.cpp probes it before calling the factory and refuses to load a .so whose version doesn't match (or is missing) instead of dlsym+reinterpret_cast blindly onto a vtable that just grew a virtual — the ABI hazard boost::dll plugins don't otherwise catch at load time. - All 4 in-tree behaviors switched to the export macro. - test/plugins/stale_abi_recovery.cpp (new): a plugin built against the old ABI, used to verify the registry actually refuses it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -169,6 +169,9 @@ RecoveryResult RecoveryBehavior::update(const robot::Time& now)
|
||||
void RecoveryBehavior::cancel()
|
||||
{
|
||||
cancel_requested_ = true;
|
||||
// Đồng bộ, trước mọi tick: đây là chỗ duy nhất một behavior có việc chạy dài được biết nó bị
|
||||
// huỷ khi caller không tick nữa (2026-09-11).
|
||||
onCancelRequested();
|
||||
}
|
||||
|
||||
RecoveryResult RecoveryBehavior::onCancel()
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*********************************************************************/
|
||||
#include <recovery_core/recovery_registry.h>
|
||||
|
||||
#include <recovery_core/recovery_abi.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <boost/dll/import.hpp>
|
||||
@@ -68,6 +70,33 @@ bool RecoveryRegistry::loadOne(const std::string& name, const std::string& type,
|
||||
|
||||
std::function<RecoveryBehavior::RecoveryBehaviorPtr()> factory;
|
||||
|
||||
// ABI guard (2026-09-11): plugin build với header RecoveryBehavior cũ có vtable ngắn hơn; nạp vào
|
||||
// runtime mới thì lời gọi virtual mới (onCancelRequested) nhảy vào byte rác — crash đúng lúc bấm
|
||||
// cancel. Tra `<type>_abi` trước; thiếu hoặc lệch thì từ chối, log LỖI, robot chạy tiếp thiếu
|
||||
// behavior này (route resolve đã biết bỏ tên thiếu).
|
||||
try
|
||||
{
|
||||
const auto abi = boost::dll::import_alias<int()>(library_path, type + "_abi",
|
||||
boost::dll::load_mode::append_decorations);
|
||||
const int plugin_abi = abi();
|
||||
if (plugin_abi != kRecoveryAbiVersion)
|
||||
{
|
||||
robot::log_error("[recovery_core] RecoveryRegistry: '%s' from '%s' was built for ABI %d but "
|
||||
"this runtime is ABI %d — refusing to load it. Rebuild the plugin against "
|
||||
"the current recovery_core headers.",
|
||||
type.c_str(), library_path.c_str(), plugin_abi, kRecoveryAbiVersion);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
robot::log_error("[recovery_core] RecoveryRegistry: '%s' from '%s' exports no '%s_abi' symbol "
|
||||
"(built before 2026-09-11 or not using RECOVERY_CORE_EXPORT_BEHAVIOR) — "
|
||||
"refusing to load it: %s",
|
||||
type.c_str(), library_path.c_str(), type.c_str(), ex.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
factory = boost::dll::import_alias<RecoveryBehavior::RecoveryBehaviorPtr()>(
|
||||
|
||||
Reference in New Issue
Block a user