Fix resource leaks when TeleopSession setup fails#782
Conversation
|
📝 Docs preview is not auto-deployed for fork PRs. A maintainer with write access to |
📝 WalkthroughWalkthrough
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/teleop_session_manager/python/teleop_session.py`:
- Around line 926-932: Update the exception-handling block in the teleop session
setup flow to catch failures from stack.__exit__, log the rollback error, and
explicitly re-raise the original error so cleanup cannot replace it; keep
self._oxr_session reset in the finally path. Add a regression test covering an
already-entered resource whose __exit__ fails during unwind and verify the setup
exception is preserved.
- Around line 922-936: Update the session context-manager entry flow around
_enter_resources to reject a nested __enter__ when the session is already
active, checking _setup_complete and/or the existing exit stack before mutating
state. Raise the appropriate re-entry error while preserving the current
setup-error cleanup behavior for the initial entry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: ac60bea7-30af-41eb-a241-d17d51498a62
📒 Files selected for processing (2)
src/core/teleop_session_manager/python/teleop_session.pysrc/core/teleop_session_manager_tests/python/test_teleop_session.py
7321e7d to
82ac840
Compare
Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
82ac840 to
35fdc4a
Compare
Description
TeleopSession.__enter__acquired OpenXR, DeviceIO, and plugin contexts onto the session-ownedExitStack. If a later setup step raised, thewithbody never started and Python did not callTeleopSession.__exit__, leaving the resources acquired so far alive.This change makes session startup transactional:
ExitStackThere is no public API change.
The parameterized regression test fails OpenXR, DeviceIO, the first plugin, and a later plugin in turn, checking exact-once reverse-order cleanup. Additional tests cover rollback cleanup failure and nested entry while preserving normal reuse after exit.
Type of change
Testing
ctest --test-dir build -R "^teleop_session_manager_" --output-on-failure --parallel 4(4/4 passed, macOS arm64, Release, Python 3.11)SKIP=check-copyright-year pre-commit run --all-filesChecklist
SKIP=check-copyright-year pre-commit run --all-filesgit commit -s) per the DCO