Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude LD_LIBRARY_PATH and PYTHONHOME when invoking subprocesses #1565

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Apr 16, 2024

During the build, the buildpack makes the config vars set on the app available to certain subprocesses (such as Django collectstatic) via the sub_env utility function. This function filters out env vars that might cause the subprocess to fail.

This change adds LD_LIBRARY_PATH and PYTHONHOME to the list of env vars that are filtered out, to prevent errors when they are set to invalid values. (Note: This filtering only affects app config vars, and not the env vars provided by buildpacks that run prior to the Python buildpack.)

In particular, very old versions of the buildpack used to set these env vars as actual app config vars (via the bin/release script), to values that no longer work:

PATH: /app/.heroku/venv/bin:/bin:/usr/local/bin:/usr/bin
PYTHONUNBUFFERED: true
LIBRARY_PATH: /app/.heroku/vendor/lib
LD_LIBRARY_PATH: /app/.heroku/vendor/lib
LANG: en_US.UTF-8
PYTHONHASHSEED: random
PYTHONHOME: /app/.heroku/venv/
PYTHONPATH: /app/

These broken app config vars have not typically caused problems since:

  1. Only Python apps created in 2012 or earlier will have them (unless someone manually sets them on an app)
  2. Static builds of Python don't rely upon LD_LIBRARY_PATH

However, as of Python 3.10 we switched to building in shared mode (see #1320), and so apps with broken config vars will otherwise see errors like the following once they upgrade Python versions:

python: error while loading shared libraries: libpython3.10.so.1.0: cannot open shared object file: No such file or directory

As seen in:
https://heroku.support/1309696
https://heroku.support/1365030

The GIT_DIR env var was removed from the filter list, since there is no need to filter it out, since it's no longer set by the build system, see #1120.

(The CNB isn't affected by this issue, and already has a test to confirm that.)

GUS-W-15519103.

@edmorley edmorley self-assigned this Apr 16, 2024
During the build, the buildpack makes the config vars set on the app
available to certain subprocesses (such as Django collectstatic) via the
`sub_env` utility function. This function filters out env vars that
might cause the subprocess to fail. (Note: This filtering only affects
app config vars, and not the env vars provided by buildpacks that run
prior to the Python buildpack.)

This change adds `LD_LIBRARY_PATH` and `PYTHONHOME` to the list of env
vars that are filtered out, to prevent errors when they are set to
invalid values.

In particular, very old versions of the buildpack used to set these env
vars as actual app config vars (via the `bin/release` script), to values
that no longer work:
https://github.com/heroku/heroku-buildpack-python/blob/27abdfe7d7ad104dabceb45641415251e965671c/bin/release#L11-L18

These broken app config vars have existed for a while, but have not
typically caused problems since static builds of Python don't rely upon
`LD_LIBRARY_PATH`.

However, as of Python 3.10 we switched to building in shared mode (see
#1320), and so apps with broken config vars will otherwise see errors
like the following when they upgrade Python versions:

```
python: error while loading shared libraries: libpython3.10.so.1.0: cannot open shared object file: No such file or directory
```

As seen in:
https://heroku.support/1365030

The `GIT_DIR` env var was removed from the filter list, since there is
no need to filter it out, since it's no longer set by the build system,
see #1120.

(The CNB isn't affected by this issue, and already has a test to confirm that.)

GUS-W-15519103.
@edmorley edmorley force-pushed the handle-broken-LD_LIBRARY_PATH branch from d5054c5 to f180263 Compare April 16, 2024 13:31
.rubocop.yml Show resolved Hide resolved
@edmorley edmorley marked this pull request as ready for review April 16, 2024 13:34
@edmorley edmorley requested a review from a team as a code owner April 16, 2024 13:34
@edmorley edmorley enabled auto-merge (squash) April 16, 2024 13:41
@edmorley edmorley merged commit 1a704d3 into main Apr 16, 2024
8 checks passed
@edmorley edmorley deleted the handle-broken-LD_LIBRARY_PATH branch April 16, 2024 15:40
@heroku-linguist heroku-linguist bot mentioned this pull request Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants