mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

[BUG]: s390x container build and runtime failures — psycopg-binary unavailable + protobuf segfault

Open akshaymohan29 opened this issue 8 months ago • 1 comments

🐞 Bug Summary

Two issues prevent ContextForge from building and running on s390x:

Issue 1 — Build: gunicorn command not found uv pip install fails silently on s390x because the postgres extra requires psycopg[c,binary]>=3.3.3, but psycopg-binary has no pre-built wheel for s390x on PyPI. The silent failure breaks the entire dependency install — gunicorn, fastapi, etc. are never installed into the virtual environment.

Issue 2 — Runtime: Segfault in protobuf UPB C extension Even after fixing the build, the container crashes silently at startup. The protobuf UPB C extension (google._upb._message) segfaults on s390x when importing OpenTelemetry protobuf definitions (common_pb2.py).


🧩 Affected Component

  • [x] Container setup (Docker/Podman/Compose)

🔁 Steps to Reproduce

You can reproduce this either on a native s390x VM or via cross-architecture emulation (QEMU).

Option A: Reproduce via QEMU (on amd64 or arm64 host)

  1. Enable QEMU multi-architecture emulation on your host:
    docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    # or for podman: podman machine init && podman machine start
    
  2. Build the image targeting s390x:
    docker buildx build --platform linux/s390x -f Containerfile.lite -t mcpgateway:s390x .
    
  3. The build succeeds, but silently skips the critical uv installation.
  4. Run the container:
    docker run --rm --platform linux/s390x mcpgateway:s390x
    
  5. Observe the ❌ FATAL: gunicorn command not found! error.

Option B: Reproduce natively (on s390x Linux VM)

  1. Build the image normally on the s390x machine:
    podman build -f Containerfile.lite -t mcpgateway:s390x .
    
  2. Run the container:
    podman run --rm localhost/mcpgateway:s390x
    
  3. Same result — container fails because gunicorn was silently skipped during build.
  4. After applying the build fix, run the container again to trigger the runtime segfault: Container exits completely silently after Configuring SQLite with pool_size=50, max_overflow=10.
  5. Run with Python's fault handler to see the crash:
    podman run --rm -it localhost/mcpgateway:s390x python3 -q -X faulthandler -c "from mcpgateway.observability import init_telemetry"
    
  6. Observe the C-extension segmentation fault:
    Fatal Python error: Segmentation fault
      File "opentelemetry/proto/common/v1/common_pb2.py", line 17 in <module>
      ...
    Extension modules: google._upb._message (total: 4)
    

🤔 Expected Behavior

The container should build successfully and spin up its Gunicorn workers to serve the application on port 4444.


🧠 Environment Info

Key Value
Version or commit main
Runtime Python 3.12, Gunicorn
Platform / OS s390x / UBI10 (Native and QEMU)
Container Podman / Docker Buildx

🧩 Fix

This PR fixes both issues securely without impacting AMD64 or ARM64 users. The fixes are contained in if [ "$(uname -m)" = "s390x" ] blocks.

Issue 1 — Containerfile.lite: Swap uv pip for standard pip on s390x. Try building psycopg[c]>=3.3.3 from source (since postgresql-devel is in the builder), with a fallback to pure-Python psycopg>=3.3.3 if missing system headers:

     && if [ "$(uname -m)" = "s390x" ]; then \
         echo "📦 Installing dependencies for s390x architecture..."; \
-        /app/.venv/bin/uv pip install ".[redis,postgres,mysql,observability,granian]"; \
+        dnf install -y libpq-devel 2>/dev/null || true; \
+        /app/.venv/bin/pip install --no-cache-dir ".[redis,mysql,observability,granian]" \
+        && (/app/.venv/bin/pip install --no-cache-dir "psycopg[c]>=3.3.3" \
+            || /app/.venv/bin/pip install --no-cache-dir "psycopg>=3.3.3"); \
     else \
         /app/.venv/bin/uv pip install ".[redis,postgres,mysql,observability,granian]"; \
     fi \

Issue 2 — docker-entrypoint.sh: Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python on s390x runtime to force Protobuf to bypass the buggy UPB C extension:

 set -euo pipefail

+# s390x: Force protobuf to use pure-Python implementation.
+# The UPB C extension (google._upb._message) segfaults on s390x when
+# importing OpenTelemetry protobuf definitions.
+if [ "$(uname -m)" = "s390x" ]; then
+    export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
+fi
+
 HTTP_SERVER="${HTTP_SERVER:-gunicorn}"

akshaymohan29 avatar Mar 17 '26 07:03 akshaymohan29

Hey! I may be able to help with this bug.

I build custom fixes for Python projects and automation systems.

If you'd like help resolving this issue quickly feel free to reach out.

Happy to take a look 👍

FocusMode-coder avatar Mar 17 '26 07:03 FocusMode-coder