Skip to content

BUG: std::bad_alloc during mamba_read_json is silently swallowed, yielding a poisoned .solv cache and false PackagesNotFoundError. #4170

@nikitakuklev

Description

@nikitakuklev

Troubleshooting docs

  • My problem is not solved in the Troubleshooting docs

Anaconda default channels

  • I do NOT use the Anaconda default channels (pkgs/* etc.)

How did you install Mamba?

Mambaforge or latest Miniforge

Search tried in issue tracker

memory bad_alloc

Latest version of Mamba

  • My problem is not solved with the latest version

Tried in Conda?

I do not have this problem with Conda, just with Mamba

Describe your issue

(disclaimer: LLM-assisted debugging - it was quite a feat to trace down)

Environment:
mamba / libmamba version: 2.5.0 (linux-64)
OS: Alma linux 9.7, Kernel 5.14.0, glibc 2.34

Description:
When evaluating repodata inside VM with overcommitted RAM, simdjson encounters a std::bad_alloc during the operator new call for parsing the json file, because the cumulative process memory exceeds the free memory.

Instead of terminating the application with a fatal Out-Of-Memory error, libmamba's exception handler catches the std::bad_alloc, abandons the JSON parse, and writes a structurally valid but entirely empty 279-byte .solv to pkgs_dirs/cache.

The SAT solver subsequently reads this empty file and outputs PackagesNotFoundError: does not exist. So you get crazy errors like 'python not found'. The user is given no indication that a memory fault occurred, and the local cache is poisoned.

GDB Backtrace:

Thread 1 "mamba" hit Catchpoint 1 (exception thrown), __cxxabiv1::__cxa_throw (obj=0x5555558a9be0, tinfo=0x7ffff7928b38 <typeinfo for std::bad_alloc>, dest=0x7ffff7779360 <std::bad_alloc::~bad_alloc()>)
#0  __cxxabiv1::__cxa_throw (...) at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:80
#1  0x00007ffff77686a2 in operator new (sz=655064704) at ../../../../libstdc++-v3/libsupc++/new_op.cc:54
#2  0x00007ffff7c270e8 in mamba::solver::libsolv::mamba_read_json(...)
#3  0x00007ffff7bf11af in mamba::solver::libsolv::Database::add_repo_from_repodata_json(...)

Expected Behavior:
If mamba_read_json encounters a std::bad_alloc, the package manager must abort the transaction immediately, exit with a non-zero status code, and surface the memory allocation error to stderr. It must never commit an empty array to the .solv cache.

mamba info / micromamba info

libmamba version : 2.5.0
          mamba version : 2.5.0
           curl version : libcurl/8.18.0 OpenSSL/3.6.1 zlib/1.3.1 zstd/1.5.7 libssh2/1.11.1 nghttp2/1.67.0 mit-krb5/1.21.3
     libarchive version : libarchive 3.8.5 zlib/1.3.1 liblzma/5.8.2 bz2lib/1.0.8 liblz4/1.10.0 libzstd/1.5.7 liblzo2/2.10 openssl/3.5.4 libb2/bundled
       envs directories : /export/<>/share/miniforge3/envs
          package cache : /export/<>/share/tmp/conda_pkgs
            environment : base (active)
           env location : /export/<>/share/miniforge3
      user config files : /export/<>/.mambarc
 populated config files : /export/<>/.condarc
                          /export/<>/share/miniforge3/.condarc
       virtual packages : __unix=0=0
                          __linux=5.14.0=0
                          __glibc=2.34=0
                          __archspec=1=x86_64_v4
               channels : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
       base environment : /export/<>/share/miniforge3
               platform : linux-64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions