Skip to content

Stop growing PATH on every Borg job on macOS - #2552

Merged
m3nu merged 2 commits into
borgbase:masterfrom
ThomasWaldmann:fix-path-growth
Sep 7, 2026
Merged

Stop growing PATH on every Borg job on macOS#2552
m3nu merged 2 commits into
borgbase:masterfrom
ThomasWaldmann:fix-path-growth

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Collaborator

Description

BorgJob.prepare_bin() appended :/opt/homebrew/bin:/usr/local/bin to os.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?

  • New test test_prepare_bin_does_not_grow_path in tests/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 --check clean.

Types of changes

  • 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)

Checklist:

  • I have read the CONTRIBUTING guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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

ThomasWaldmann and others added 2 commits September 5, 2026 20:00
`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>
@m3nu
m3nu merged commit 670bb89 into borgbase:master Sep 7, 2026
5 checks passed
@ThomasWaldmann
ThomasWaldmann deleted the fix-path-growth branch September 7, 2026 15:04
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.

2 participants