Linux

Containerized Python worker aborts with SIGABRT only when launched from systemd timer unit

Environment

Environment

Ubuntu 22.04 host, Docker 20.10.25, Python 3.11 image with a compiled C-extension used by worker. systemd timer configured to run docker run --rm myworker:latest on schedule (Type=oneshot, launched as root).

Symptoms

Symptoms

When systemd timer triggers, the container starts but the worker process inside receives SIGABRT then exits; container stops with exit code 134. Running identical docker run command interactively from shell succeeds and worker runs to completion.

Observations

Observations

journalctl shows systemd unit finished; no OOM killer entries in dmesg or syslog. Core produced inside container points to abort in native extension (abort()). Running docker run under sudo in an interactive non-login shell works. Adding --init to docker run didn't change behaviour when started via timer. No AppArmor denials logged.

Already attempted

Already attempted

Increased systemd limits (LimitNOFILE, TasksMax), tried launching timer as a different user, ran container with --privileged and added CAP_SYS_ADMIN; replicated environment variables from interactive shell in unit file; used docker logs and docker inspect. None consistently prevented SIGABRT.

Question

Question

Which environment or cgroup differences imposed by systemd timers commonly cause process aborts inside containers? How can I safely reproduce the systemd-start environment for iterative debugging and identify the failing subsystem in the C-extension without rebuilding production images?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
emmahacks Answer
user
Posted 1mo ago • 0 confirmations

Start by reproducing the systemd-start environment locally: run systemd-run --scope --unit=tmpdocker /usr/bin/docker run ... so you get the same cgroup/limits. If the container still aborts, add a tiny wrapper script as the container ENTRYPOINT that writes env and /proc/self/limits to a mounted directory before launching the worker — compare that with your interactive run. If ulimits differ, set LimitNOFILE/TasksMax in the unit; if env vars are missing, add Environment= or EnvironmentFile=. Verify by running the timer for several iterations and checking the saved logs. Roll back any raised limits if they cause resource exhaustion on the host.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Missing runtime environment variables (LANG/LC_ALL, LD_LIBRARY_PATH) or different PATH causing the C-extension to load incompatible library and abort. 65%
Systemd-imposed cgroup limits or differing RLIMITs (nofile, nproc, memlock) cause the extension to detect lack of resources and abort. 55%
Absence of a controlling TTY/pty or different stdin/stdout/stderr handling causing library assertion in native code path. 30%

Summary

Differences between interactive shells and systemd-launched processes frequently include environment variables, ulimits, cgroup resource restrictions, and absence of a full PAM/login session. A native extension abort suggests it encountered an unexpected runtime condition (missing resource, invalid locale, lack of entropy, or file-descriptor inheritance). systemd timers run services without a TTY, may set different limits and may not allocate pts/tty; additionally, systemd may launch processes with a minimal environment (LANG, PATH) and with different /proc/self/limits via cgroups which can trigger library-level assertions in C code.

Suggested Fixes

Diagnostic step 1
Re-run the container under systemd-run --unit=debug --slice=machine.slice --pty --scope -- /usr/bin/docker run ... to mimic systemd runtime and capture logs interactively.
Diagnostic step 2
Export the full environment seen by interactive run (env) and inject it into the unit file (Environment= or EnvironmentFile=) to compare results.
Diagnostic step 3
Configure the systemd unit with LimitNOFILE= and TasksMax= set high, and set KillMode=process to avoid group kills during debugging.

Continue troubleshooting

Matched from the title, description and tags