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

pex packed binaries hanging forever at __del()__ from MktempTeardownRegistry #2641

Open
gebi opened this issue Jan 15, 2025 · 5 comments
Open
Assignees
Labels

Comments

@gebi
Copy link

gebi commented Jan 15, 2025

Hi,

We wanted to start using pex for our binaries but the packed binaries are hanging on MktempTeardownRegistry:__del()__ ofte enough that none of our ci pipeline runs finish successfully.

The CI builds are executed in docker containers where pex binaries are hanging sometimes.

Sadly we did not manage to reproduce it locally or in a smaller scope.

There are no concurrent pex invocations or other pex binaries running inside the container.

Binaries are created with pex --include-tools --sh-boot --disable-cache ... but also tried without --sh-boot and without --disable-cache but did not change behaviour.

We also tried various env variables like
PEX_ROOT=$(mktemp -d) ... did not help
PEX_VENV=1 ... did not help
PEX_MAX_INSTALL_JOBS=1 ... did not help
_PEX_FILE_LOCK_STYLE=bsd ... did not help
PEX_VERBOSE=9 ... still hangs, output below

Any ideas on how to debug this further?
If necessary we could execute debugging things rather quickly to help find the issue, but for the issue itself we are unsure on how to debug this any further.

environment

Debian 11 bullseye
python 3.9.2 from debian
pex packed binary executed inside docker 27.5.0

logs / outputs

lslocks just shows access.lck locked by the hanging pex binary

% lslocks |grep pex
python3.9        5626  FLOCK      READ  0     0   0 /root/.cache/pex/access.lck

open files from pex dir

% lsof +D  /root/.cache/pex/
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME
python3.9 5626 root  mem    REG  0,240    16064 22925 /root/.cache/pex/installed_wheels/0/0306137b3437c482b384743524f0244fc0a839f2543f05eeb3d4f7c6073e8a05/charset_normalizer-3.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl/charset_normalizer/md.cpython-39-x86_64-linux-gnu.so
python3.9 5626 root  mem    REG  0,240    68152 26692 /root/.cache/pex/installed_wheels/0/90b4da8b2b341200d19a9c035f2831790abea9d999fc02ece0b172f3ff829fdd/setproctitle-1.3.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl/setproctitle/_setproctitle.cpython-39-x86_64-linux-gnu.so
python3.9 5626 root    6wR  REG  0,240        0     2 /root/.cache/pex/access.lck

debugging the hanging binary we got the following informations

(gdb) py-bt
Traceback (most recent call first):
  File "/root/.cache/pex/unzipped_pexes/1/35c46b1d3ed582b4e96ad0098116379cfcc42787/.bootstrap/pex/common.py", line 165, in __del__
    def __del__(self):
  Garbage-collecting
(gdb) py-bt-full
#3 Frame 0x7f52d9df3520, for file /root/.cache/pex/unzipped_pexes/1/35c46b1d3ed582b4e96ad0098116379cfcc42787/.bootstrap/pex/common.py, line 165, in __del__ (self=<MktempTeardownRegistry(_registry={}, _lock=<_thread.RLock at remote 0x7f52dadbecf0>, _getpid=<built-in method getpid of module object at remote 0x7f52db5059f0>, _rmtree=<function at remote 0x7f52dae40d30>) at remote 0x7f52dadbecd0>)
    def __del__(self):
#12 Garbage-collecting
(gdb) info threads
  Id   Target Id                                    Frame 
* 1    Thread 0x7f52db88f0c0 (LWP 5626) "python3.9" 0x00007f52dbc197b2 in pthread_cond_wait@@GLIBC_2.3.2 ()
   from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) py-list
 160            self._lock = threading.RLock()
 161            self._getpid = os.getpid
 162            self._rmtree = shutil.rmtree
 163            atexit.register(self.teardown)
 164    
>165        def __del__(self):
 166            # type: () -> None
 167            self.teardown()
 168    
 169        def register(self, path):
 170            # type: (str) -> str

pex verbose 9 output

...
pex: un-imported <module 'pex.atomic_directory' from '/root/.cache/pex/unzipped_pexes/1/35c46b1d3ed582b4e96ad0098116379cfcc42787/.bootstrap/pex/atomic_directory.py'>
pex: un-imported <module 'pex' from '/root/.cache/pex/unzipped_pexes/1/35c46b1d3ed582b4e96ad0098116379cfcc42787/.bootstrap/pex/__init__.py'>
pex: Re-imported pex from ['/root/.cache/pex/installed_wheels/0/0ab4161e93cec01ce2f4bf70bf81fafa4854d1699f091ab1c126506e66e7a5d0/pex-2.28.1-py2.py3-none-any.whl/pex']
pex: PYTHONPATH contains:
pex:     /root/.cache/pex/unzipped_pexes/1/35c46b1d3ed582b4e96ad0098116379cfcc42787
pex:   * /usr/lib/python39.zip
pex:     /usr/lib/python3.9
pex:     /usr/lib/python3.9/lib-dynload
pex:     /root/.cache/pex/installed_wheels/0/b4b730bfe1091e078d59bd61d29343389775d1d8d53667ba07677070d39b44a2/annotated_types-0.7.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/2982aa547f3457a56ae69066213dd3d5c3b4e0a12a9605730592c893f30c8bf1/ansible_core-2.15.13-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/3ae51a68a6e898c3765479d450b3598ad19ba8b1562269c5b8cb32a1eebad051/jinja2-3.1.4-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/22f2909902bcf99931c285880f84f9b6c7b2ae6e575ba7dd9cd1df82f27dd1df/MarkupSafe-3.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/039733ceba4c06aab2550ecac1841ea73cb3a39f0ebe79aa12cdea8798968c61/PyYAML-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/c3a434ca8539497aab6285a3b45250a6a642b5017a7701882822b2a762357cb3/cryptography-43.0.3-cp39-abi3-manylinux_2_28_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/095cfaea9e2ac7089be96901981c888f0c3a790bf2c3fd90069ae77fd00840e3/cffi-1.17.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/e6109cc25af0537a33208f2d8d5603aa9d2eaa69a9f8aaa0427c4705b7cb2f04/pycparser-2.22-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/980e8e7b5313a0fa0d65864bf8a8f20bbfe1a0598846d29f9cbe88379a58750a/packaging-24.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/63b9e47643c8ce0df3edc9340f4cb04dd4a516d9ca58af610192958201448d77/resolvelib-1.0.1-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/98b12f79aad90d629d4ce310eac514c4467f3ab1ae78b9f1b3f8344f4b1c6cff/importlib_resources-5.0.7-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/cf0c770d2c2fb298986580946091e487f84b86ea10c4969382d2a2961e46e288/ansible-8.7.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/91710aacd0a9f819d982999219cf1f80b0995bc7e19ea474dce165dbc8a8caff/backports.tarfile-1.2.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/339204d4a6ebb12301f65c6bf98a4db01bda08e3d930f58c912f1cdcfa9703ba/bcrypt-4.2.1-cp39-abi3-manylinux_2_28_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/dca1ae8d29ba0a65baa7a20d371f23554d3cc27419e093d36076f6154124b3e2/certifi-2024.8.30-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/0306137b3437c482b384743524f0244fc0a839f2543f05eeb3d4f7c6073e8a05/charset_normalizer-3.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/8ab007356e466bf716f661c3ad7954130bcc92d6fa326ab3cf424a3dd5d83254/click-8.1.7-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/9ab6a4b9cd0e7d265c430959c5314614029ba1a2cf012a2a3bc4837f7a6a0de6/decorator-5.1.1-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/8c38234e116ff9b0806b19b634057c48c69e46997a0a0cf7933c5f0aea04aab6/Deprecated-1.2.15-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/867369aa5cb14302e14324e63afd8d0efa59fde1f91fb0498e058633fb16666e/wrapt-1.17.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/66eb3e64a218c8b400e55f98b5305b1be40d0fbdd95bb64281c58fdd1c837e33/distro-1.9.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/2878f28146b48615b7384f450b63c7e7e9711f3823312d79391fd54b37292af2/docker-7.1.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/2f57f4ae5920a2f5f55a8f4971fe010b00cb2a30f8ab9c572826150fa309c450/requests-2.32.3-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/7c60d05cda1bf40836124b2018f4bbbfcab10a8c761890952f6cb9ae3fe7a77a/idna-3.10-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/f60f021e46df20f0f58e26b80d9369032e635b616dca8713a9e4fc8fa2e7adda/urllib3-2.2.3-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/19ec0a70ad948f1af2c42434d20b3695864250ab51f670d8535dc59db4412b60/etcd3gw-2.4.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/b1c6ce63894ad4b62d9d11368528e90d22ae5473ee1fd6a2388d11259f589643/futurist-3.0.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/26b1b1ff0564dc7f745f6e0ac3d923839b39c30ed556a0f31ff419757839a443/pbr-6.1.0-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/bdbf6f82d45c6f82121a00fb44861651a64fcb2bbbb64f879e0ec32b442921ec/fabric-3.2.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/269dc32d5f08b5eeeef889dd5220c62c17ef0c9a2ff0a2bde229ac546c946244/invoke-2.2.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/9b963024695fe0cb2365031044fd70441197cd9e8aab35df2204de5771edacf7/paramiko-3.5.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/12d73b075e741519b3f72844712e373b1009b58a7906f9c9cec7826b66fc1a5f/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/24f736da4c7e831df279ee75bf90a5fa5a427da1480660772a7d3b8cdb603d22/gitdb-4.0.11-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/2a04afc9788324f755b576f3c81c72952e49dbf23e68fcf8230a7816a93495ac/smmap-5.0.1-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/4ff4bc8d8fd73913af547f02f420d67d4c45b1d01491a58de9b505e8e1345245/GitPython-3.1.43-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/d6936ca355a72a8aea19adc28612d4389bd4816ced6d5f3175c8e9ef30b5f1f7/humanize-4.11.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/431a57671e9623fa78ba17a68e2388ddb0c5727139fa1218bd21b2bef7759861/importlib_metadata-8.5.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/2cb5715dfe4b791c6c0324128d1862d3448ffee8885128d9cdf20d64ffce59b0/zipp-3.21.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/54c5f7af869ff5e33d753cd904374235514275bd1b9b0ad358914098e97547df/inflect-7.0.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/5a0f828acc9aa9acffc4375e19feb944ac86a47ffd15b9edd685ba34c5a9b8fd/pydantic-2.10.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/86f1c0b917ba19ccd9b12204163325566b71e3774acbf8df3e87750983fc0a96/pydantic_core-2.27.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/ab87cc50d4264524df94030d479d1501922ac3d258a1d09cff936840137acd76/typing_extensions-4.12.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/19ae531cd7c3fbd55681024bc80d4e50272179aaa0b9d1cb2c5a39937c82bbff/jaraco.classes-3.4.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/d65fda122ac25930b9a30ca2b6d8c1a399483d6bad1bb7e9cec34f4a1152d8ba/more_itertools-10.5.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/023754d39ee8293cc7bfb253478fe3235eebdf910a434cf2bfe0e8012f058896/jaraco.context-6.0.1-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/62b06a938b537aba61db12b7b3e39617efbd406a24fde542cff6e4465f1b2a16/jaraco.functools-4.1.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/4fed67045e4a84e19df0843adcd86c4f04c299671d64801227401b19c78908ab/jeepney-0.8.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/fb035340fcc70f197a14ff942dc0e8ba01c3fb4ad03fb6c217a75dcb7ed92b5f/keyring-25.5.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/a73d3f4b0542bd7c50b9f4e39097faa417446e01758240d96bc64d1af498bbad/SecretStorage-3.3.3-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/95c3079d3ccfb033c1c082ca25f335980c59048058f29b0114cad4b2434185f1/markdown_it_py-3.0.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/9d6f6069070b70647164b999996f91f35bc2f3319f980b3345a197ed4521b429/mdurl-0.1.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/0ab4161e93cec01ce2f4bf70bf81fafa4854d1699f091ab1c126506e66e7a5d0/pex-2.28.1-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/f56e4718032ee33e4b8790edcdb0be1deaacda261ecf505ff226c71c8dec3a3c/prometheus_client-0.21.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/ad83311b3c004c5d1e276844198f8303788c08ab9004f56b41b73f81dfc3989d/pygments-2.18.0-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/ced8f6f021b89284ed17cd6e84bd8ddbf99e93fdb59556fb41cf35eb45899d18/PyMySQL-1.1.1-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/fbaaf64849976060549a757aabe642087aa86f97fed10a7f3c05ef8be0f15572/pyroute2-0.7.12-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/1011c5d2c8f51f701bcdec5163ebcb225ece43c69f00f64280575b11c05e1155/python_apt-0.0.0-cp39-cp39-linux_x86_64.whl
pex:     /root/.cache/pex/installed_wheels/0/39ddbecd5afe4d79170d0ec014ca3ba4aea75ad4646ce36eb791070be0f1dd66/python_dateutil-2.9.0.post0-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/a8dffba69ff16231827d7133867794d7e85295e22c36fbdc496b3d80d6d8d2cc/six-1.16.0-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/fc634e52c1c21442eb2d9e15e60ee9e338a3d50636ed872fa194eb1830e88a49/python_dotenv-1.0.1-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/11875d3ca7f149d2b8db430a514c098653cf4cb1d9c368072f432494f9f96a0a/python_slugify-8.0.4-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/3866ba4ec0079317b2c98b9b5bcea9f43fe4a1fb78feabf1724ac34f0fd0de8f/text_unidecode-1.3-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/ba7bf6138bba68b9bb127d8ac5a0b4f2314ba291aca1f33f6bc5c81efda8c436/rich-13.9.4-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/f7d57e5b2bd4a00ed16815c41dc3c198d7740c80514bfa99b1957f9d625f694e/semver-3.0.2-py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/e8f50c427097b7659e2a2569911140a5ba71bbe7488b9035ec307b3681911680/sentry_sdk-1.45.1-py2.py3-none-any.whl
pex:     /root/.cache/pex/installed_wheels/0/90b4da8b2b341200d19a9c035f2831790abea9d999fc02ece0b172f3ff829fdd/setproctitle-1.3.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
pex:     /root/.cache/pex/unzipped_pexes/1/35c46b1d3ed582b4e96ad0098116379cfcc42787/.bootstrap
pex:   * - paths that do not exist or will be imported via zipimport

requirements.txt pex is executed with

annotated-types==0.7.0 ; python_version >= "3.9" and python_version < "3.13"
ansible-core==2.15.13 ; python_version >= "3.9" and python_version < "3.13"
ansible==8.7.0 ; python_version >= "3.9" and python_version < "3.13"
backports-tarfile==1.2.0 ; python_version >= "3.9" and python_version < "3.12"
bcrypt==4.2.1 ; python_version >= "3.9" and python_version < "3.13"
certifi==2024.8.30 ; python_version >= "3.9" and python_version < "3.13"
cffi==1.17.1 ; python_version >= "3.9" and python_version < "3.13"
charset-normalizer==3.4.0 ; python_version >= "3.9" and python_version < "3.13"
click==8.1.7 ; python_version >= "3.9" and python_version < "3.13"
colorama==0.4.6 ; python_version >= "3.9" and python_version < "3.13" and platform_system == "Windows"
cryptography==43.0.3 ; python_version >= "3.9" and python_version < "3.13"
decorator==5.1.1 ; python_version >= "3.9" and python_version < "3.13"
deprecated==1.2.15 ; python_version >= "3.9" and python_version < "3.13"
distro==1.9.0 ; python_version >= "3.9" and python_version < "3.13"
docker==7.1.0 ; python_version >= "3.9" and python_version < "3.13"
etcd3gw==2.4.2 ; python_version >= "3.9" and python_version < "3.13"
fabric==3.2.2 ; python_version >= "3.9" and python_version < "3.13"
futurist==3.0.0 ; python_version >= "3.9" and python_version < "3.13"
gitdb==4.0.11 ; python_version >= "3.9" and python_version < "3.13"
gitpython==3.1.43 ; python_version >= "3.9" and python_version < "3.13"
humanize==4.11.0 ; python_version >= "3.9" and python_version < "3.13"
idna==3.10 ; python_version >= "3.9" and python_version < "3.13"
importlib-metadata==8.5.0 ; python_version >= "3.9" and python_version < "3.12"
importlib-resources==5.0.7 ; python_version >= "3.9" and python_version < "3.10"
inflect==7.0.0 ; python_version >= "3.9" and python_version < "3.13"
invoke==2.2.0 ; python_version >= "3.9" and python_version < "3.13"
jaraco-classes==3.4.0 ; python_version >= "3.9" and python_version < "3.13"
jaraco-context==6.0.1 ; python_version >= "3.9" and python_version < "3.13"
jaraco-functools==4.1.0 ; python_version >= "3.9" and python_version < "3.13"
jeepney==0.8.0 ; python_version >= "3.9" and python_version < "3.13" and sys_platform == "linux"
jinja2==3.1.4 ; python_version >= "3.9" and python_version < "3.13"
keyring==25.5.0 ; python_version >= "3.9" and python_version < "3.13"
markdown-it-py==3.0.0 ; python_version >= "3.9" and python_version < "3.13"
markupsafe==3.0.2 ; python_version >= "3.9" and python_version < "3.13"
mdurl==0.1.2 ; python_version >= "3.9" and python_version < "3.13"
more-itertools==10.5.0 ; python_version >= "3.9" and python_version < "3.13"
packaging==24.2 ; python_version >= "3.9" and python_version < "3.13"
paramiko==3.5.0 ; python_version >= "3.9" and python_version < "3.13"
pbr==6.1.0 ; python_version >= "3.9" and python_version < "3.13"
pex==2.28.1 ; python_version >= "3.9" and python_version < "3.13"
prometheus-client==0.21.0 ; python_version >= "3.9" and python_version < "3.13"
pycparser==2.22 ; python_version >= "3.9" and python_version < "3.13"
pydantic-core==2.27.1 ; python_version >= "3.9" and python_version < "3.13"
pydantic==2.10.2 ; python_version >= "3.9" and python_version < "3.13"
pygments==2.18.0 ; python_version >= "3.9" and python_version < "3.13"
pymysql==1.1.1 ; python_version >= "3.9" and python_version < "3.13"
pynacl==1.5.0 ; python_version >= "3.9" and python_version < "3.13"
pyroute2==0.7.12 ; python_version >= "3.9" and python_version < "3.13"
python-dateutil==2.9.0.post0 ; python_version >= "3.9" and python_version < "3.13"
python-dotenv==1.0.1 ; python_version >= "3.9" and python_version < "3.13"
python-slugify==8.0.4 ; python_version >= "3.9" and python_version < "3.13"
pywin32-ctypes==0.2.3 ; python_version >= "3.9" and python_version < "3.13" and sys_platform == "win32"
pywin32==308 ; python_version >= "3.9" and python_version < "3.13" and sys_platform == "win32"
pyyaml==6.0.2 ; python_version >= "3.9" and python_version < "3.13"
requests==2.32.3 ; python_version >= "3.9" and python_version < "3.13"
resolvelib==1.0.1 ; python_version >= "3.9" and python_version < "3.13"
rich==13.9.4 ; python_version >= "3.9" and python_version < "3.13"
secretstorage==3.3.3 ; python_version >= "3.9" and python_version < "3.13" and sys_platform == "linux"
semver==3.0.2 ; python_version >= "3.9" and python_version < "3.13"
sentry-sdk==1.45.1 ; python_version >= "3.9" and python_version < "3.13"
setproctitle==1.3.4 ; python_version >= "3.9" and python_version < "3.13"
six==1.16.0 ; python_version >= "3.9" and python_version < "3.13"
smmap==5.0.1 ; python_version >= "3.9" and python_version < "3.13"
text-unidecode==1.3 ; python_version >= "3.9" and python_version < "3.13"
typing-extensions==4.12.2 ; python_version >= "3.9" and python_version < "3.13"
urllib3==2.2.3 ; python_version >= "3.9" and python_version < "3.13"
win-inet-pton==1.1.0 ; python_version >= "3.9" and python_version < "3.13" and platform_system == "Windows"
wrapt==1.17.0 ; python_version >= "3.9" and python_version < "3.13"
zipp==3.21.0 ; python_version >= "3.9" and python_version < "3.12"
git+https://salsa.debian.org/apt-team/[email protected]#egg=python-apt

many thx for reading this till the end :) !

@jsirois jsirois self-assigned this Jan 15, 2025
@jsirois
Copy link
Member

jsirois commented Jan 15, 2025

Addressing your hang debugging 1st:

The hang you observe is in a destructor that grabs no locks. It only calls:

  1. os.getpid
  2. Uses the result from 1 to get a list of directories from a dict.
  3. calls shutil.rmtree for each directory found in 2.

So there is 0 Pex code in that call graph to be causing the hang. In your particular case, the dict in step 2 shows as empty; so there is not even any shutil.rmtree call. The only calls that can hang are either os.getpid or the dict lookup. The only generic hang condition I know of in destructors in Python occurs when you spawn a thread from within your __del__ implementation. That is not going on here.

As such, I'm going to throw away your hang debug info - it does not appear to point usefully at anything.

Pex debugging:

One way to solve this or at least narrow scope to things other than Pex is to get Pex out of the picture as early as possible. If the docker image for CI is prepared by you with the packed PEX in it, you can:

PEX_TOOLS=1 your.pex venv --bin-path prepend --site-packages-copies /create/venv/here

Then, instead of running your.pex, run /create/venv/here/pex or /create/venv/here/bin/your-console-script. If using the /create/venv/here/pex entry point, that's the sum total of PEX code that runs in that 1 file. You can inspect it and edit it as needed if the hang persists.

If, instead, the packed PEX is created while running in the docker image in CI, you should create the Pex with:

pex --sh-boot --venv prepend --venv-site-packages-copies ...

The venv options cause the PEX to install itself in as traditional a venv as possible on 1st run. The --sh-boot causes the PEX bootstrap code in the PEX to be skipped on every PEX run after the 1st. So on the 1st run, PEX code will execute, but only to install the venv at which point it will execv into the venv. On every run after that, the /bin/sh shebang in the PEX will execute and it will execv into the venv - 0 PEX code involved.

In either case, when running in --venv mode, PEX involvement in the process is gone very early in the process. The minute you have any of your code running in that case, PEX is out of the picture via an execv jump. You process has replaced the address space completely. It's only when running as a traditional zipapp (whether zipped, packed or loose), that there is PEX teardown code like MktempTeardownRegistry that can run after your process code.

@gebi let me know if any of that helps your debug journey.

@gebi
Copy link
Author

gebi commented Jan 16, 2025

sry for the very long mail, after reading it again it sounded much harsher than intended... seems i just concentrated way too much on getting all the little details correct.

many thx for your help and debugging suggestions, we'll debug further and update the issuere here if we find anything usefull.

@jsirois
Copy link
Member

jsirois commented Jan 16, 2025

sry for the very long mail, after reading it again it sounded much harsher than intended...

I didn't read it that way at all. You provided alot of facts. The more the better. The more you leave out the longer the back and forth takes. Ideally you dump all relevant state from your end so I can "see" what you see. The devil in that detail is always knowing what's relevant. Here, I think the only relevant bits you left out were:

  1. Is the CI job running in a container pre-prepared by you or a stock one?
  2. Is the lock up happening before your code in the packed PEX runs or after it starts running?

@jsirois
Copy link
Member

jsirois commented Jan 24, 2025

@gebi any more data to report?

@jsirois
Copy link
Member

jsirois commented Jan 30, 2025

@gebi I'm going to close this since there's been no further data reported. Please do re-open though if you do find more data for me to look at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants