Skip to content

Fix resource leaks when TeleopSession setup fails#782

Open
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/teleop-session-enter-cleanup
Open

Fix resource leaks when TeleopSession setup fails#782
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/teleop-session-enter-cleanup

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description

TeleopSession.__enter__ acquired OpenXR, DeviceIO, and plugin contexts onto the session-owned ExitStack. If a later setup step raised, the with body never started and Python did not call TeleopSession.__exit__, leaving the resources acquired so far alive.

This change makes session startup transactional:

  • acquire resources on a temporary ExitStack
  • on failure, unwind the temporary stack in reverse order and clear the stale OpenXR reference
  • keep propagating the setup error even if a child suppresses it or raises during rollback; rollback failures are logged
  • transfer stack ownership to the session only after every setup step succeeds
  • reject nested entry so an active session stack cannot be overwritten

There 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

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-files

Checklist

  • I have read and understood the contribution guidelines
  • I have run the linter and formatter with SKIP=check-copyright-year pre-commit run --all-files
  • Documentation is not required because the public API is unchanged
  • I have added tests that prove the fix works
  • I have signed off all commits (git commit -s) per the DCO

@github-actions

Copy link
Copy Markdown
Contributor

📝 Docs preview is not auto-deployed for fork PRs.

A maintainer with write access to NVIDIA/IsaacTeleop can deploy a preview by
commenting /preview-docs on this PR. Once deployed, the preview
will live at:

https://nvidia.github.io/IsaacTeleop/preview/pr-782/

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

TeleopSession.__enter__ now acquires OpenXR, DeviceIO, and plugin resources through a temporary ExitStack. Failed acquisition closes the partially populated stack, clears the OpenXR session, and re-raises the exception. Successful acquisition stores the stack and marks setup complete. A parametrized test verifies reverse-order cleanup and state reset across multiple failure stages.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • NVIDIA/IsaacTeleop#770: Both changes update TeleopSession and OpenXR session lifecycle cleanup around context-manager teardown.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: transactional TeleopSession setup to prevent resource leaks on failure.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a67ed4 and 7321e7d.

📒 Files selected for processing (2)
  • src/core/teleop_session_manager/python/teleop_session.py
  • src/core/teleop_session_manager_tests/python/test_teleop_session.py

Comment thread src/core/teleop_session_manager/python/teleop_session.py
Comment thread src/core/teleop_session_manager/python/teleop_session.py
@fallintoplace
fallintoplace force-pushed the fix/teleop-session-enter-cleanup branch from 7321e7d to 82ac840 Compare July 16, 2026 04:33
@fallintoplace fallintoplace changed the title Roll back TeleopSession resources when setup fails Fix resource leaks when TeleopSession setup fails Jul 16, 2026
Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
@fallintoplace
fallintoplace force-pushed the fix/teleop-session-enter-cleanup branch from 82ac840 to 35fdc4a Compare July 16, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant