Bug 23684 – std.process.spawnProcess fails if ulimit is too large

Status
NEW
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-02-10T23:58:52Z
Last change time
2024-12-01T16:41:04Z
Assigned to
No Owner
Creator
Jan Jurzitza
Moved to GitHub: phobos#10515 →

Comments

Comment #0 by d.bugs — 2023-02-10T23:58:52Z
This code fails: ```d import std.process; void main() { auto pid = spawnProcess(["ls"]); while (true) {} } ``` with `std.process.ProcessException@std/process.d(1196): Failed to allocate memory (Cannot allocate memory)` when the ulimit max open files, divided by 8, is equal or larger than the available memory. This happened when trying to spawn a process inside a docker container: install rocky linux (rhel) 768M mem + 768M swap install docker docker run --rm -it debian:bullseye apt-get update && apt-get install -y gcc ldc create d file ldc2 -run test.d Problem: it tries to allocate `RLIMIT_NOFILE * pollfd.sizeof` bytes to pass to poll to try which FDs are open to close them to not accidentally inherit them. However RLIMIT_NOFILE is on this platform = 1073741816 Workaround: Config.inheritFDs will make std.process not try to close them, thus avoiding the malloc, thus avoiding the crash. There should probably be a check if RLIMIT_NOFILE is very big and in that case probably try to chunk the polling or do a brute force approach or just see how other standard libraries implemented this issue.
Comment #1 by robert.schadek — 2024-12-01T16:41:04Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10515 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB