Repository navigation
Ensure rs-dds-adapter is killed in finally block to prevent leaks - #15237
Conversation
…ted test can't leak it
sysrsbuild-gh-agentic
left a comment
There was a problem hiding this comment.
Test review body
| with test.closure( 'Stop rs-dds-adapter', on_fail=test.ABORT ): | ||
| # Kill directly, not via test.closure: an aborted test would make the closure throw and skip the kill. | ||
| if adapter_process: | ||
| try: |
There was a problem hiding this comment.
Test inline comment
sysrsbuild-gh-agentic
left a comment
There was a problem hiding this comment.
Test 2 comments
| with test.closure( 'Stop rs-dds-adapter', on_fail=test.ABORT ): | ||
| # Kill directly, not via test.closure: an aborted test would make the closure throw and skip the kill. | ||
| if adapter_process: | ||
| try: |
There was a problem hiding this comment.
Comment on if adapter_process line
| if adapter_process: | ||
| try: | ||
| # Try graceful termination first (SIGTERM lets adapter release DDS resources on Linux) | ||
| adapter_process.send_signal( signal.SIGTERM ) |
There was a problem hiding this comment.
Comment on send_signal context line
sysrsbuild-gh-agentic
left a comment
There was a problem hiding this comment.
[rs-agentic bot] Automated review of PR #15237 — unit-tests/dds/adapter/test-depth.py
The fix is correct and well-targeted. The root cause (aborting test leaving test_in_progress set, causing test.closure in finally to throw before the kill runs) is accurately diagnosed, and moving the cleanup out of test.closure into a plain if/try/finally is the right approach.
A few observations below (inline + general).
General notes (not inline):
-
Cleanup no longer appears in test report — By removing
test.closure('Stop rs-dds-adapter'), the termination step is no longer recorded in the test results. This is intentional and correct, but worth being aware of: if the graceful kill fails andkill_all_dds_adapters()is also slow, there will be no test-step failure surfaced — only alog.e()line. Acceptable trade-off given the bug fix, but document it. -
Missing regression test — No test is added to simulate the abort scenario (e.g. mock a wait-for-device timeout that triggers
abort(), then verifyrs-dds-adapteris not left running). Consider adding a test to prevent regressions of this specific leak path.
| with test.closure( 'Stop rs-dds-adapter', on_fail=test.ABORT ): | ||
| # Kill directly, not via test.closure: an aborted test would make the closure throw and skip the kill. | ||
| if adapter_process: | ||
| try: |
There was a problem hiding this comment.
[rs-agentic bot] Enhancement — Good guard added.
This if adapter_process: check is an improvement over the original (which would raise AttributeError on None.send_signal() if the adapter never started). However, note a subtle behavioral change: in the original code, even when adapter_process was None, the inner finally: kill_all_dds_adapters() would still execute (after the AttributeError propagated through test.closure). With the new code, if adapter_process is None, the entire block is skipped — including the kill_all_dds_adapters() safety-net.
In practice this is safe (the top-of-script cleanup and the _sigterm_handler cover leftover processes), but consider moving the kill_all_dds_adapters() call outside the if adapter_process: guard for symmetry:
finally:
if adapter_process:
try:
adapter_process.send_signal( signal.SIGTERM )
adapter_process.wait( timeout=2 )
log.d( 'rs-dds-adapter terminated gracefully' )
except (subprocess.TimeoutExpired, Exception) as e:
log.e( f'Error terminating rs-dds-adapter: {e}' )
kill_all_dds_adapters() # always run, even if adapter_process is None| if adapter_process: | ||
| try: | ||
| # Try graceful termination first (SIGTERM lets adapter release DDS resources on Linux) | ||
| adapter_process.send_signal( signal.SIGTERM ) |
There was a problem hiding this comment.
[rs-agentic bot] Potential Bug / Enhancement — Redundant exception type + log level mismatch.
(Note: this comment targets the except (subprocess.TimeoutExpired, Exception) as e: clause at line ~121, just below the visible diff hunk — anchored here as the nearest diff line.)
subprocess.TimeoutExpired is a subclass of Exception, so listing it explicitly before Exception is redundant — Exception already catches it. This was inherited from the original code but worth cleaning up.
More importantly, both a graceful-shutdown timeout and an unexpected exception result in log.e(...). A TimeoutExpired (adapter took >2s to die before force-kill) is often expected behavior, not an error. Consider distinguishing them:
except subprocess.TimeoutExpired:
log.w( 'rs-dds-adapter did not terminate gracefully within 2s; force-killing' )
except Exception as e:
log.e( f'Unexpected error terminating rs-dds-adapter: {e}' )This gives cleaner signal in CI logs and avoids false-alarm ERROR lines on slow adapter shutdown.
When test-dds-adapter-depth aborts (e.g. the wait-for-device timeout), the cleanup was wrapped in a
test.closure. On an aborted testabort()callssys.exit()before clearingtest_in_progress, so opening that closure infinallythrows"test case is already running"and the kill never runs — leakingrs-dds-adapter, which then poisons later tests in the session.Fix: kill the adapter directly in
finally(plain try/except +kill_all_dds_adapters()), so it can't be blocked by leftover test state. No other behavior change.