Skip to content

Close replaced root-logger handlers in configure_logging - #8809

Merged
AntoineRichard merged 2 commits into
isaac-sim:mainfrom
Sonica-B:fix/logger-close-replaced-handlers
Oct 26, 2026
Merged

AntoineRichard merged 2 commits into
isaac-sim:mainfrom
Sonica-B:fix/logger-close-replaced-handlers

Conversation

@Sonica-B

@Sonica-B Sonica-B commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

isaaclab.utils.configure_logging removes the root logger's existing handlers before it installs its own, but it never closes them. A logging.FileHandler that is removed but not closed keeps its log file open for the rest of the process. On Linux this goes unnoticed. On Windows an open file cannot be deleted, so two tests in source/isaaclab/test/utils/test_logger.py fail on a native Windows 11 checkout:

  • test_configure_logging_with_file: tempfile.TemporaryDirectory() cleanup raises PermissionError: [WinError 32] on the open custom_logs/isaaclab_*.log.
  • test_configure_logging_default_log_dir: the test's own os.remove(log_file_path) raises the same error.

This PR closes each removed handler right after removeHandler, which is what logging.basicConfig(force=True) does. It also updates the docstring to say so. Both tests now release their log file by reconfiguring before cleanup. test_configure_logging_with_file also asserts that the replaced file handler is closed (file_handler.stream is None), so the regression is caught on Linux too.

Closing a StreamHandler (for example the one on sys.stdout, or pytest's capture handlers) does not close its stream, so only file-backed handlers actually release anything.

Fixes #8808

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Not applicable (no visual change).

Testing

Windows 11, Python 3.12.12, CPU-only PyTorch 2.11.0, no Isaac Sim.

Baseline revision: main @ 4a281f3, the main commit I tested on. The baseline run used logger.py from that commit together with the tests from this PR. This branch was prepared on 4a281f3 and rebased onto 259e1a8 (the current PR base) before opening. source/isaaclab/isaaclab/utils/logger.py and source/isaaclab/test/utils/test_logger.py are identical at 4a281f3 and 259e1a8 (git diff 4a281f3 259e1a8 over both files is empty), so the baseline result applies to the current base.

failed passed
Baseline: main @ 4a281f3, test_logger.py 2 (test_configure_logging_with_file, test_configure_logging_default_log_dir, both PermissionError: [WinError 32]) 12
Candidate: this PR at a740799, test_logger.py 0 14
uv run python -m pytest source/isaaclab/test/utils/test_logger.py -q

At the same baseline, -m unit over source/isaaclab/test/utils gives the same 36 failures with and without this change, plus the two logger tests on the baseline. All 36 come from the environment: omni (Isaac Sim) is missing, torch is a CPU build, and torchvision is missing. That sweep was run before the rebase; after the rebase and after the latest commit I re-ran only test_logger.py (14 passed) and the pre-commit hooks on the touched files.

Checklist

Docker and GPU tests run on demand. Push the commits you want tested, then
comment run-ci on the pull request.

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Code owners for /source/isaaclab/ (per .github/CODEOWNERS): ooctipus, AntoineRichard, kellyguo11, StafaH, pbarejko, fatimaanes.

configure_logging removed the root logger's existing handlers without closing them, so the log file opened by an earlier call stayed open for the life of the process. On Windows an open file cannot be deleted, which made test_configure_logging_with_file and test_configure_logging_default_log_dir fail there. Close the removed handlers, as logging.basicConfig(force=True) does, and have both tests release their log file before cleanup.

Signed-off-by: Sonica-B <[email protected]>
@Sonica-B
Sonica-B requested a review from a team October 25, 2026 09:17
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Oct 25, 2026
@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

configure_logging now closes root-logger handlers after removing them, releasing files held by earlier calls.

  • Reconfiguring logging closes old handlers and releases their files.
  • The contributor list now includes Shreya Boyane.

Reviews (1) · Last reviewed commit: "Close replaced root-logger handlers in c..." · Reviewed by Greptile

@isaaclab-review-bot isaaclab-review-bot 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.

Isaac Lab Review Bot

Needs attention: Test quality (1). Other reviewed categories look good.

  • PR description: The body matches the diff, but its tested baseline differs from the PR base; identify the actual baseline revision and give explicit baseline and candidate failure counts.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: Implementation looks good.
  • Style consistency: Style consistency looks good.
  • Test quality: The regression assertion is necessary, but cleanup runs only after successful assertions; place reconfiguration in a finally block so Windows file-lock errors cannot mask the original failure.

Minor fixes needed. Posted 1 inline finding.

Automated review; human maintainers own approval decisions.


# Reconfiguring closes the replaced file handler, so the temporary directory can be removed
# (an open file cannot be deleted on Windows)
configure_logging(logging_level="DEBUG", save_logs_to_file=False)

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.

🟡 Warning · Test Quality — Make test cleanup exception-safe

The reconfiguration runs only after every assertion passes. An earlier failure leaves the file handler open, so TemporaryDirectory cleanup raises PermissionError on Windows and masks the real failure. Move it into a finally block in…

Reconfigure logging in a finally block so a failed assertion cannot leave the file handler open, which on Windows makes TemporaryDirectory cleanup raise PermissionError and mask the original failure.

Signed-off-by: Sonica-B <[email protected]>

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the PR @Sonica-B!

@AntoineRichard

Copy link
Copy Markdown
Collaborator

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Oct 26, 2026
@maxkra15
maxkra15 self-requested a review October 26, 2026 11:05

@maxkra15 maxkra15 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.

thanks, look correct!

@AntoineRichard
AntoineRichard merged commit fae9611 into isaac-sim:main Oct 26, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] configure_logging leaves replaced root-logger handlers open (log file locked on Windows)

3 participants