fix(libwaterlinked): harden TCP command handling - #32
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the libwaterlinked TCP client’s command/response and callback handling to improve reliability under concurrency, fast responses, timeouts, and connection-loss scenarios, and updates the ROS driver wiring to pass the new timeout configuration.
Changes:
- Extend
WaterLinkedClientto support a configurable command-response timeout and track pending requests with deadlines. - Add mutex protection around pending command requests and around callback registration/iteration.
- Update the driver to pass the timeout for both connection setup and command responses, and clarify the parameter description.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| waterlinked_dvl_driver/src/waterlinked_dvl_driver.cpp | Passes the timeout into the updated WaterLinkedClient constructor (connection + command). |
| waterlinked_dvl_driver/src/waterlinked_dvl_driver_parameters.yaml | Clarifies that the timeout applies to both connection and command responses. |
| libwaterlinked/src/client.cpp | Implements pending-request locking, deadline-based timeouts, connection-loss failure, and callback locking. |
| libwaterlinked/include/libwaterlinked/client.hpp | Updates the public API and internal pending-request tracking structures to support command timeouts and locking. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thank you for the pull request - and sorry for taking so long to review it. In general it looks sane, with protecting requests and handling of socket connection. It seems that the locking of request_mutex_ when calling the blocking send() could be avoided, and rather use a send_mutex to protect writing to the socket. Nothing that can't be fixed after merge, but I'll keep it open for a little while longer. |
Summary
This PR improves reliability of the Water Linked TCP client and callback handling.
The TCP command path had several reliability risks:
pending_requests_was accessed from multiple threads without locking.socket()succeeded.Changes
pending_requests_withrequest_mutex_.Validation
Tested with:
colcon build --packages-up-to waterlinked_dvl_driver colcon test --packages-select libwaterlinked --event-handlers console_direct+ colcon test-result --verbose