Fix dangling‐capture in TestNodeConfig::complete_func to eliminate flaky IDLE returns #967
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.
Summary
When using TestNode for JSON-driven substitution rules, the default complete_func lambda in
TestNodeConfig was capturing this (the address of a temporary). After move-constructing into the member _test_config, that pointer became dangling and often returned IDLE from onRunning(), triggering a LogicError. This patch changes the capture to copy return_status by value, fully eliminating the UB and making the test nodes reliably return SUCCESS or FAILURE as configured.
Background / Motivation
Reported in issue #927: “TestNode sometimes returns IDLE onRunning()”
Reproduced in a minimal repo: test nodes intermittently returned IDLE even when configured for SUCCESS
Added file/minitrace loggers, saw onRunning() → IDLE and confirmed it came from complete_func()
Debugging revealed
complete_func = [this](){…}
pointed at a destroyed temporaryChanges
Before:
After:
Testing
Added file- and minitrace-logger in user code to capture every tick.
Wrote a small BT with a single <Action ID="Test" …/> substituted via JSON.
Verified 1st tick RUNNING, 2nd tick SUCCESS.
Ran full scenario suite — no more LogicError.
Related issues Issues:
#927: #927
and maybe
#930: #930
Thanks for reviewing 🙏 Let me know if you’d like any tweaks!