Skip to content

musllinux wheel fails to load on Alpine: “initial-exec TLS resolves to dynamic definition” when importing cachebox #41

Closed

Description

@mpihelgas

Problem description

Importing cachebox v5.2.0 inside an Alpine (musl) container raises an error:

ImportError: Error relocating /venv/lib/python3.12/site-packages/cachebox/_core.cpython-312-x86_64-linux-musl.so: (null): initial-exec TLS resolves to dynamic definition in /venv/lib/python3.12/site-packages/cachebox/_core.cpython-312-x86_64-linux-musl.so

Some initial workarounds I already tested

  • Same application loads fine on Debian-based container base image.
  • Reverting to an earlier version (e.g., v5.1.0) of cachebox avoids the error on Alpine.

Environment

  • Base image: python:3.12-alpine (musl libc)
  • Python: 3.12
  • cachebox: 5.2.0 (wheel from PyPI)
  • Package with the cachebox dependency: openfeature-provider-flagd v0.2.6

Details

From the cachebox v.5.2.0 release changelog we can see:

Starting now, cachebox uses mimalloc as the default allocator for some targets ( thanks to @chirizxc, #37)

Mimalloc’s TLS model (initial-exec) is known to break with musl when the library is dlopened; upstream recommends rebuilding with -DMI_LOCAL_DYNAMIC_TLS=ON or switching to the local-dynamic model.

Summary

The published cachebox v5.2.0 wheel seems to fail consistently on the Alpine-based image.
Would it be possible to disable the mimalloc feature for musllinux wheels or adjust the mimalloc build flags so the extension can load on musl?

References

Activity

  1. chirizxc commented on Dec 30, 2025

    @chirizxc
    Contributor

    seems need to add local_dynamic_tls

    [dependencies.mimalloc]
    version = "0.1.48"
    features = ["v3", "override", "local_dynamic_tls"]
    optional = true
  2. awolverp commented on Dec 31, 2025

    @awolverp
    Owner

    Thank you for reporting ❤️ It will be fixed now

  3. chirizxc commented on Dec 31, 2025

    @chirizxc
    Contributor

    @awolverp Should we add tests for this?

    FROM docker.io/library/python:3.13-alpine
    
    WORKDIR /app
    
    ENV UV_LINK_MODE=copy \
        UV_COMPILE_BYTECODE=1 \
        UV_PYTHON_DOWNLOADS=0
    
    COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
    
    RUN uv pip install cachebox==5.2.0 --system
    
    RUN cat <<'EOF' > /app/example.py
    import cachebox
    
    print(f"{cachebox.__version__}")
    
    cache = cachebox.FIFOCache(maxsize=128)
    cache["key"] = "value"
    assert cache["key"] == "value"
    EOF
    
    RUN addgroup -S user && adduser -S -G user user
    RUN chown -R user:user /app
    USER user
    
    CMD ["python", "example.py"]

    https://github.com/lava-sh/toml-rs/blob/main/.github%2Fworkflows%2Fci.yml#L158-L186

  4. chirizxc commented on Dec 31, 2025

    @chirizxc
    Contributor
    Image

    5.2.0

  5. chirizxc commented on Dec 31, 2025

    @chirizxc
    Contributor
    Image

    5.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions