You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several places changed a socket's receive timeout for a single request and restored it by hand. In the G5 dashboard client, commandGenerateFlightReport() and commandGenerateSupportFile() only restored it after a normal return or an UnexpectedResponse. A TimeoutException or UrException from the request left the 180 s / 600 s timeout active for all later commands.
TCPSocket::temporaryReceiveTimeout() now returns a ScopedReceiveTimeout guard that restores the previous timeout when it goes out of scope, including during exception unwinding. If no timeout was set before, the socket has no receive timeout afterwards. The restore does not allocate, as it runs in a destructor. An overload takes a std::chrono duration, and comm::toTimeval() converts durations to timeval.
Changes per component:
RTDEClient: the file-local ScopedMinimumReceiveTimeout is replaced by the new guard
DashboardClientImplG5: connect() and the long-running commands use the guard, which removes seven manual restores
DashboardClientImplX: does not use TCPSocket, so it gets a local RAII guard that replaces the catch (...)/rethrow blocks
Also initialises the timeval in DashboardClientImplG5::getConfiguredReceiveTimeout(), which left tv_usec uninitialised when no timeout was configured.
Tests
tcp_socket_tests: the guard restores a previous and an unset timeout, also on exceptions; a moved guard restores once; the chrono overload and toTimeval() work; the timeout is applied to a connected socket
dashboard_client_mock_tests: regression test with a fake dashboard server that shuts down during commandGenerateFlightReport(); without this change the timeout stays at 180 s
The G5 integration tests against URSim were not run locally.
Several places changed a socket's receive timeout for a single request and
restored it by hand. In the G5 dashboard client, commandGenerateFlightReport()
and commandGenerateSupportFile() only restored it after a normal return or an
UnexpectedResponse. A TimeoutException or UrException from the request left
the 180 s / 600 s timeout active for all later commands.
TCPSocket::temporaryReceiveTimeout() now returns a ScopedReceiveTimeout guard
that restores the previous timeout when it goes out of scope, including during
exception unwinding. If no timeout was set before, the socket has no receive
timeout afterwards. The restore does not allocate, as it runs in a destructor.
An overload takes a std::chrono duration, and comm::toTimeval() converts
durations for the remaining callers.
Users of the new guard:
- RTDEClient: replaces the file-local ScopedMinimumReceiveTimeout
- DashboardClientImplG5: connect() and the long-running commands, which
removes seven manual restores
- DashboardClientImplX: does not use TCPSocket, so it gets a local guard that
replaces the catch(...)/rethrow blocks
Also initialises the timeval in DashboardClientImplG5::
getConfiguredReceiveTimeout(), which left tv_usec uninitialised when no
timeout was configured.
ClosesUniversalRobots#609
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012icwri1zuEqdphNtL4XVuT
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Medium Risk
Touches core socket I/O and dashboard/RTDE handshake paths; behavior change is intentional (timeout always restored) with broad new tests, but long-running command timeouts are sensitive to regressions.
Overview
Adds RAII-scoped receive timeouts on TCPSocket via ScopedReceiveTimeout and temporaryReceiveTimeout(), plus comm::toTimeval() for chrono conversion. The guard restores the prior timeout (or “no timeout”) when it is destroyed, including on exceptions; restore uses silent setsockopt so destructors do not log or allocate.
Call sites drop hand-rolled save/restore: G5 dashboard connect() (welcome polling), long generate flight report / generate support file commands; RTDE boot handshake (raiseReceiveTimeout replaces ScopedMinimumReceiveTimeout); PolyScope X gets a local ScopedDashboardReceiveTimeout for commandPowerOn and commandGenerateFlightReport. G5 also zero-inits getConfiguredReceiveTimeout()’s timeval.
Tests cover guard restore (including exceptions, moves, connected sockets, failed setsockopt) and a G5 regression where a failed flight report must not leave a 180 s timeout active.
Reviewed by Cursor Bugbot for commit a081b69. Bugbot is set up for automated code reviews on this repo. Configure here.
Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.
As a nested class the guard can reach the socket's private receive
timeout and restore path, so the two friend declarations between the
guard and TCPSocket are no longer needed. The constructor becomes
public; temporaryReceiveTimeout() stays the usual way to create one.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
❌ Patch coverage is 91.54930% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.97%. Comparing base (bbbe4f5) to head (a081b69).
✅ All tests successful. No failed tests found.
Hi @guti97
Thanks for the PR and your contribution.
I have made a small change to the design as what to avoid having friend classes, to avoid complex class structures in the future.
As the ScopedTimeout only is used togher with the TCPSocket, I have moved it and made it a nested class instead.
Run the SO_RCVTIMEO check for an unset timeout on Windows as well, and
add a read that blocks until data arrives after the guard restored an
unset timeout. Also check that a long-running G5 dashboard command
reports its temporary timeout when it times out.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The cleanup guard can terminate the process if socket-option restoration triggers an allocation or log-handler exception in its implicitly noexcept destructor, so restoration must use the non-logging socket wrapper.
The guard restores the timeout in its destructor, also while an
exception unwinds. setupOptions() logs a warning when a socket option
cannot be set, which allocates and calls a log handler that may throw,
so a failing setsockopt could terminate the process. The restore now
only sets SO_RCVTIMEO and ignores errors, and is noexcept.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An exception during timeout setup can prevent the guard from completing construction, leaving the temporary receive timeout stored instead of restoring the previous value.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Restore the previous receive timeout if guard construction throws
src/comm/tcp_socket.cpp:641
If a socket-option failure causes warning formatting or a registered log handler to throw, setReceiveTimeout() has already overwritten recv_timeout_. The guard never finishes construction, so its destructor cannot restore the previous timeout and the temporary value remains stored. Catch exceptions from this call, restore previous_ through the non-throwing restoreReceiveTimeout() helper, and rethrow.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The timeout guard can fail during construction without restoring the previous receive timeout, leaving the temporary value in effect for later requests or reconnects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Several places changed a socket's receive timeout for a single request and restored it by hand. In the G5 dashboard client,
commandGenerateFlightReport()andcommandGenerateSupportFile()only restored it after a normal return or anUnexpectedResponse. ATimeoutExceptionorUrExceptionfrom the request left the 180 s / 600 s timeout active for all later commands.TCPSocket::temporaryReceiveTimeout()now returns aScopedReceiveTimeoutguard that restores the previous timeout when it goes out of scope, including during exception unwinding. If no timeout was set before, the socket has no receive timeout afterwards. The restore does not allocate, as it runs in a destructor. An overload takes astd::chronoduration, andcomm::toTimeval()converts durations totimeval.Changes per component:
RTDEClient: the file-localScopedMinimumReceiveTimeoutis replaced by the new guardDashboardClientImplG5:connect()and the long-running commands use the guard, which removes seven manual restoresDashboardClientImplX: does not useTCPSocket, so it gets a local RAII guard that replaces thecatch (...)/rethrow blocksAlso initialises the
timevalinDashboardClientImplG5::getConfiguredReceiveTimeout(), which lefttv_usecuninitialised when no timeout was configured.Tests
tcp_socket_tests: the guard restores a previous and an unset timeout, also on exceptions; a moved guard restores once; the chrono overload andtoTimeval()work; the timeout is applied to a connected socketdashboard_client_mock_tests: regression test with a fake dashboard server that shuts down duringcommandGenerateFlightReport(); without this change the timeout stays at 180 sThe G5 integration tests against URSim were not run locally.
Closes #609