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

pipenv update on linux using python 3.10 leaves files in /tmp/ #5180

Closed
dbaxa opened this issue Jul 20, 2022 · 4 comments · Fixed by #5210
Closed

pipenv update on linux using python 3.10 leaves files in /tmp/ #5180

dbaxa opened this issue Jul 20, 2022 · 4 comments · Fixed by #5210
Labels
Priority: High This item is high priority and should be resolved quickly. Type: Bug 🐛 This issue is a bug.

Comments

@dbaxa
Copy link

dbaxa commented Jul 20, 2022

Be sure to check the existing issues (both open and closed!), and make sure you are running the latest version of Pipenv.

Issue description

pipenv update leaves temp files in /tmp/ which should not persist/remain after python exits.

Expected result

No temp files related to pipenv remain in /tmp/

Actual result

pipenv temp files are left in /tmp

Steps to replicate

pipenv update


Please run $ pipenv --support, and paste the results here. Don't put backticks (`) around it! The output already contains Markdown formatting.
pipenv --support

$ pipenv --support

Pipenv version: '2022.7.4'

Pipenv location: '/home/user/.virtualenvs/myvenv/lib/python3.10/site-packages/pipenv'

Python location: '/home/user/.virtualenvs/myvenv/bin/python'

Python installations found:

  • 3.10.4: /home/user/.virtualenvs/myvenv/bin/python
  • 3.10.4: /home/user/.virtualenvs/myvenv/bin/python3
  • 3.10.4: /home/user/.virtualenvs/myvenv/bin/python
  • 3.10.4: /home/user/.virtualenvs/myvenv/bin/python3
  • 3.10.4: /usr/bin/python3
  • 3.10.4: /usr/bin/python
  • 3.10.4: /bin/python3
  • 3.10.4: /bin/python
  • 2.7.18: /usr/bin/python2
  • 2.7.18: /usr/bin/python2.7
  • 2.7.18: /bin/python2
  • 2.7.18: /bin/python2.7

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.10.4',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '5.15.0-41-generic',
 'platform_system': 'Linux',
 'platform_version': '#44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022',
 'python_full_version': '3.10.4',
 'python_version': '3.10',
 'sys_platform': 'linux'}

System environment variables:

  • SHELL
  • LANGUAGE
  • PWD
  • LOGNAME
  • XDG_SESSION_TYPE
  • MOTD_SHOWN
  • VIRTUALENVWRAPPER_SCRIPT
  • HOME
  • LANG
  • LS_COLORS
  • _VIRTUALENVWRAPPER_API
  • VIRTUAL_ENV
  • VIRTUALENVWRAPPER_WORKON_CD
  • SSH_CONNECTION
  • WORKON_HOME
  • LESSCLOSE
  • XDG_SESSION_CLASS
  • TERM
  • LESSOPEN
  • LIBVIRT_DEFAULT_URI
  • USER
  • VIRTUALENVWRAPPER_PROJECT_FILENAME
  • SHLVL
  • XDG_SESSION_ID
  • XDG_RUNTIME_DIR
  • PS1
  • SSH_CLIENT
  • MAVEN_OPTS
  • XDG_DATA_DIRS
  • BROWSER
  • PATH
  • VIRTUALENVWRAPPER_HOOK_DIR
  • DBUS_SESSION_BUS_ADDRESS
  • SSH_TTY
  • IRBRC
  • OLDPWD
  • GOPATH
  • ES_HOME
  • _
  • PIP_SHIMS_BASE_MODULE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PIP_PYTHON_PATH
  • PYTHONDONTWRITEBYTECODE
  • PYTHONFINDER_IGNORE_UNSUPPORTED
  • PIPENV_VERBOSITY

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /home/user/.virtualenvs/myvenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/user/.local/bin/
  • SHELL: /bin/bash
  • LANG: en_AU.UTF-8
  • PWD: /home/user/.virtualenvs/myvenv/lib/python3.10/site-packages/pipenv
  • VIRTUAL_ENV: /home/user/.virtualenvs/myvenv

@dbaxa
Copy link
Author

dbaxa commented Jul 20, 2022

This issue seems to be related to the use of vistir.path.create_tracked_tempfile in pipenv/environment.py. It seems that inside _TrackedTempfileWrapper.cleanup self._finalizer.detach() returns false and so the file is not deleted (see pipenv/vendor/vistir/path.py).

@matteius matteius added Priority: High This item is high priority and should be resolved quickly. Type: Bug 🐛 This issue is a bug. labels Jul 25, 2022
@dqkqd
Copy link
Contributor

dqkqd commented Jul 28, 2022

I've checked using assert not os.path.isfile(tmpfile_path) and saw that temporary file is properly deleted after the call tmpfile.close(). So cleanup function is working fine.
I think the issue is that subprocess_run create a new temporary file using the same filename without deleting it.

tmpfile = vistir.path.create_tracked_tempfile(suffix=".json")
tmpfile.close()
tmpfile_path = make_posix(tmpfile.name)
py_command = self.build_command(
python_lib=True, python_inc=True, scripts=True, py_version=True
)
command = [self.python, "-c", py_command.format(tmpfile_path)]
c = subprocess_run(command)

Should we call os.remove at the end of function to explicit delete that file? I could create a PR for this.

@matteius
Copy link
Member

That would be great @dbaxa -- I suspect there are other places where sub process is not cleaning up tmp data as well beyond just this .json file. Here is what my TMP folder looks like after clearing it out just the other day:
image

@dqkqd
Copy link
Contributor

dqkqd commented Jul 30, 2022

Sorry for late response. I created a PR for this.

I don't have such folders as @matteius does. Unless I interrupt pytest while it's still running.
I use linux and have a lot of .pem files inside /tmp after running tests, but it should be fixed as described in python/cpython#93353

So I think just make sure .json files are not leaking is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High This item is high priority and should be resolved quickly. Type: Bug 🐛 This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants