Repository navigation
Close replaced root-logger handlers in configure_logging - #8809
Conversation
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]>
[Medium impact] This PR appears safe to merge. Summary
Reviews (1) · Last reviewed commit: "Close replaced root-logger handlers in c..." · Reviewed by Greptile |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
🟡 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
left a comment
There was a problem hiding this comment.
Thanks a lot for the PR @Sonica-B!
|
run-ci |
Description
isaaclab.utils.configure_loggingremoves the root logger's existing handlers before it installs its own, but it never closes them. Alogging.FileHandlerthat 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 insource/isaaclab/test/utils/test_logger.pyfail on a native Windows 11 checkout:test_configure_logging_with_file:tempfile.TemporaryDirectory()cleanup raisesPermissionError: [WinError 32]on the opencustom_logs/isaaclab_*.log.test_configure_logging_default_log_dir: the test's ownos.remove(log_file_path)raises the same error.This PR closes each removed handler right after
removeHandler, which is whatlogging.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_filealso 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 onsys.stdout, or pytest's capture handlers) does not close its stream, so only file-backed handlers actually release anything.Fixes #8808
Type of change
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, themaincommit I tested on. The baseline run usedlogger.pyfrom 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.pyandsource/isaaclab/test/utils/test_logger.pyare identical at 4a281f3 and 259e1a8 (git diff 4a281f3 259e1a8over both files is empty), so the baseline result applies to the current base.main@ 4a281f3,test_logger.pytest_configure_logging_with_file,test_configure_logging_default_log_dir, bothPermissionError: [WinError 32])test_logger.pyAt the same baseline,
-m unitoversource/isaaclab/test/utilsgives 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, andtorchvisionis missing. That sweep was run before the rebase; after the rebase and after the latest commit I re-ran onlytest_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-cion the pull request.pre-commitchecks withuv run isaaclab --formatsource/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bump package versions — CI handles that)CONTRIBUTORS.mdor my name already exists thereCode owners for
/source/isaaclab/(per.github/CODEOWNERS):ooctipus,AntoineRichard,kellyguo11,StafaH,pbarejko,fatimaanes.