Repository navigation
Conversation
in - Reverse Interface - Script Command Interface - Trajectory Point Interface This fixes a shutdown-race with an in-flight message coming in to the TCPServer
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #632 +/- ##
==========================================
+ Coverage 83.40% 83.96% +0.55%
==========================================
Files 127 128 +1
Lines 8559 8569 +10
Branches 3913 3913
==========================================
+ Hits 7139 7195 +56
+ Misses 998 964 -34
+ Partials 422 410 -12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
🟡 Changes recommended
In-flight callbacks can access destroyed subclass state, shutdown can terminate if wakeup socket allocation fails, and deterministic teardown regression tests are missing.
3 open issues
What changed in this PR
Addresses shutdown races in TCP-backed control interfaces by stopping the server worker before callback-related members are destroyed.
Changes:
- Add explicit shutdown calls to the reverse, script-command, and trajectory-point interface destructors.
- Update public destructor declarations and lifecycle documentation.
- Remove redundant log messages when the TCP server’s listening socket is already closed.
| File | Description |
|---|---|
src/control/trajectory_point_interface.cpp |
Stop the worker before trajectory callbacks are destroyed. |
src/control/script_command_interface.cpp |
Stop the worker before tool-contact callback state is destroyed. |
src/control/reverse_interface.cpp |
Stop the worker before callback-related base members are destroyed. |
src/comm/tcp_server.cpp |
Remove redundant already-closed socket logging. |
include/ur_client_library/control/trajectory_point_interface.h |
Declare and document the explicit destructor. |
include/ur_client_library/control/script_command_interface.h |
Declare and document the explicit destructor. |
include/ur_client_library/control/reverse_interface.h |
Replace the defaulted destructor declaration and update its documentation. |
Review effort: Balanced
| // The TCP worker calls messageCallback / disconnectionCallback, which use members declared after | ||
| // server_. Join that thread here so those members are still alive. ~TCPServer would otherwise do | ||
| // it too late, after they have already been destroyed. | ||
| server_.shutdown(); |
| // The TCP worker calls messageCallback / disconnectionCallback, which use members declared after | ||
| // server_. Join that thread here so those members are still alive. ~TCPServer would otherwise do | ||
| // it too late, after they have already been destroyed. | ||
| server_.shutdown(); |
| // The TCP worker calls messageCallback / disconnectionCallback, which use members declared after | ||
| // server_. Join that thread here so those members are still alive. ~TCPServer would otherwise do | ||
| // it too late, after they have already been destroyed. | ||
| server_.shutdown(); |
There was a problem hiding this comment.
🟡 Changes recommended
The teardown tests do not reliably detect callback-list destruction and can hang on timeout because the callback-release guard is installed too late.
5 open issues
Join workers before callback state is destroyed Test does not explicitly detect destruction of the callback list · New Timeout can hang teardown before the callback release guard is installed · New Add regression tests for teardown during in-flight callbacks Ensure shutdown completes when wakeup socket allocation fails
Review effort: Balanced
| auto destroyed = last_copy_destroyed; | ||
| auto is_entered = entered; | ||
| auto may_finish = release; | ||
| auto saw = saw_destroyed; | ||
| auto ok = token_ok; | ||
| is_entered->store(true); | ||
| while (!may_finish->load()) | ||
| { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(1)); | ||
| } | ||
| saw->store(destroyed->load()); |
| void destroyWhileCallbackIsPaused(std::unique_ptr<Interface>& interface, CallbackLifetime& lifetime, | ||
| const std::shared_ptr<std::atomic<bool>>& destructor_started) | ||
| { | ||
| waitFor([&]() { return lifetime.entered->load(); }, std::chrono::seconds(2)); |


This affects
This fixes a shutdown-race with an in-flight message coming in to the TCPServer