[BUG]: s390x container build and runtime failures — psycopg-binary unavailable + protobuf segfault
🐞 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)
- 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 - Build the image targeting s390x:
docker buildx build --platform linux/s390x -f Containerfile.lite -t mcpgateway:s390x . - The build succeeds, but silently skips the critical
uvinstallation. - Run the container:
docker run --rm --platform linux/s390x mcpgateway:s390x - Observe the
❌ FATAL: gunicorn command not found!error.
Option B: Reproduce natively (on s390x Linux VM)
- Build the image normally on the s390x machine:
podman build -f Containerfile.lite -t mcpgateway:s390x . - Run the container:
podman run --rm localhost/mcpgateway:s390x - Same result — container fails because gunicorn was silently skipped during build.
- 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. - 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" - 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}"
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 👍