conda / conda/constructor

Test crash when importing from conda_interface.py with mamba 2.8.1

Open
#1,319 0 comments 0 reactions 0 assignees View on GitHub
type::bug
Dominant language
Python
Stars
497
Forks
181
Avg merge
1d 16h
Merged PRs (30d)
17

Description

### Checklist

- [x] I added a descriptive title
- [x] I searched open reports and couldn't find a duplicate

### What happened?

While working in https://github.com/conda/constructor/pull/1314 I ran into segmentation fault when running `pytests` when the Python interpreter is shutting down.

```
(test) robin@:~/repos$ PYTHONFAULTHANDLER=1 pytest -q constructor/tests/ -m "not examples"
................................................................sssssssssssssssss.sssssssssss..................ssss....s..ssssssssssss.........................sssssssssssssssssssss [ 77%]
ssssssssssssssssssssssssssssssss...........s....... [100%]

[pytest-split] Stored test durations in /.../.test_durations

===================================================================================== warnings summary =====================================================================================
tests/test_main.py::test_dry_run
tests/test_main.py::test_installer_type_flag_valid
/home/robin/miniconda3/envs/test2/lib/python3.11/contextlib.py:105: PendingDeprecationWarning: conda.common.io.env_vars is pending deprecation and will be removed in 27.3.
self.gen = func(*args, **kwds)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
132 passed, 99 skipped, 54 deselected, 2 warnings in 6.34s
Segmentation fault (core dumped)
```

After a lot of debugging, it seems to be a cocktail of components required to get this to happen. First I noticed this in our CI runners **only** on macOS and Ubuntu for Python 3.10 and Python 3.11 (every other job passed). It also seems to be triggered when you import a new function from `conda_interface.py`, even though the function in this situation does nothing.

## To reproduce
```
robin@:~/repos/constructor$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.4 LTS (Noble Numbat)"
...
```
1. Add these changes https://github.com/conda/constructor/commit/2febbe7b5011696c224405edebaff8b005c234b5. Note how I have added a dummy function, and simply imported it to trigger the error.
2. `conda create -n test python=3.11 constructor pytest pytest-mock libmamba=2.8.1 pytest-split -c conda-forge`
3. `pip install -e ./constructor`
4. `PYTHONFAULTHANDLER=1 pytest -q constructor/tests/ -m "not examples"`

I can mention that if I install `libmamba=2.3.2` there is **no** segmentation fault.

### Additional Context

I also ran this a bit via `gdb` earlier:
```
Thread 1 "python" received signal SIGSEGV
#0 ?? () in libmambapy/bindings...so
#1 ?? () in libmambapy/bindings...so
#2 mamba::logging::stop_logging(mamba::logging::stop_reason) in libmamba.so.4
#3 mamba::Context::~Context() in libmamba.so.4
#4 ?? () in libmambapy/bindings...so
#5 __run_exit_handlers (...) at exit.c:108
#6 __GI_exit
#7-9 libc startup / _start
```
I believe that this tells us the crash happens during process exit (`__run_exit_handlers` → `exit()`), not during any test itself. I spent a lot of time trying to create a minimal reproducer based on this information but I had no luck - it's also strange how this is triggered when I add the changes in the commit (link 1) above).

Finally, if it helps anyone reading this issue, the disassembly at the crash instruction (from Claude Code):
```
mov (%rbx),%rdi ; load pointer from vector element
=> mov (%rdi),%rax ; CRASH: dereference that pointer to get vtable
call *0x18(%rax) ; virtual function call through vtable
add $0x10,%rbx ; advance to next vector element (16-byte stride)
cmp %rbx,%rbp
jne ... ; loop
```

Contributor guide

Open the contributing guide

Research direction

Apply commit 2febbe7b5011696c224405edebaff8b005c234b5, then run the listed pytest command from constructor/tests/ with Python 3.10 or 3.11 and libmamba 2.8.1. Start with conda_interface.py and the exit-time stack showing libmamba logging and Context destruction; compare against libmamba 2.3.2. Done means a reproducible cause or narrowed compatibility boundary for the segmentation fault.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.