Stop growing PATH on every Borg job on macOS - #2552
Merged
Merged
Conversation
`BorgJob.prepare_bin()` appended `:/opt/homebrew/bin:/usr/local/bin` to `os.environ['PATH']` unconditionally. It runs at least twice per job, so PATH grew by ~60 bytes per job for the lifetime of the process and the ever longer value was copied into the environment of every Borg subprocess. Only append the directories that are still missing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BorgJob.prepare_bin()appended:/opt/homebrew/bin:/usr/local/bintoos.environ['PATH']unconditionally. It runs at least twice per job (prepare()and__init__()), so in a long-running instance PATH grows by ~60 bytes per Borg job for the lifetime of the process (11 KB after 150 backups in a test run) and the ever longer value is copied into the environment of every Borg subprocess. Now only the directories that are still missing are appended, so repeated calls are no-ops.Related Issue
Found while investigating Vorta's memory use for borgbackup/borg#10328 (see also #2551). No separate issue; the change is a two-line fix with a regression test.
Motivation and Context
Unbounded growth of a process-wide variable in a tray app that runs for weeks, and an ever-growing environment handed to
borg.How Has This Been Tested?
test_prepare_bin_does_not_grow_pathintests/unit/test_borg.py: PATH is unchanged by repeated calls and contains no duplicate entries.pytest tests/unit/test_borg.py: 2 passed (macOS 15, Python 3.11).ruff check/ruff format --checkclean.Types of changes
Checklist:
I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.
🤖 Generated with Claude Code