System V IPC objects not cleaned up with Darwin Sandbox #691
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
ux
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#691
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
The darwin sandbox does not clean up System V IPC objects.
Steps To Reproduce
On a darwin system:
ipcs -ma
and see the left-over shared memory segment belonging to a build user.Expected behavior
ipcs -ma
should not return any left-over shared memory segments.nix --version
outputI only have access to the nix-community darwin builder, so can't test with "lix on darwin". I am pretty sure lix should be affected, too, though.
Additional context
More details about my analysis:
The Linux sandbox mentions IPC cleanup explicitly:
- The IPC namespace prevents the builder from communicating
with outside processes using SysV IPC mechanisms (shared
memory, message queues, semaphores). It also ensures
that all IPC objects are destroyed when the builder
exits.
Various tickets which are all caused by this:
Reported for CppNix in https://github.com/NixOS/nix/issues/12548. I am not sure about the process here, whether lix becomes aware of bugs raised in CppNix or whether raising them here as well is appropriate.
Just realized that.. to be able to hit the exact bug here, you'd probably need to backport https://github.com/NixOS/nix/pull/10878 first, which apparently hasn't happened, yet - but should be easy to do?
that sandbox change got (relatively soft-) rejected here because it's an effectively deprecated feature on macOS that allows random communication between derivations. you might be able to find it, someone filed a bug requesting said port.
thank you for raising this bug. do we have any knowledge of how we could actually clean up those ipc objects left by dead processes in practice? like, which APIs exist for this? this is one of the most neglected parts of macOS so I'm not optimistic of it being nice to fix.
cc @lilyball about macos
I can list them with
ipcs
and remove them withipcrm
;). I don't really know about the APIs, just want to point out that there could also be another angle at this, discussed in https://github.com/NixOS/nixpkgs/issues/371242#issuecomment-2676179689.TLDR: Why does PostgreSQL running inside the sandbox doesn't get a chance to clean up itself? It seems to be killed immediately, but maybe there could be a way to stop those processes a bit "nicer", giving them time to cleanup?
Of course, doing this at the sandbox level, would be much better, because it would also stop badly-behaving programs.
Edit: "Time for cleanup" kind of rings a bell with #678... where the shutdown is also not entirely clean.
FTR: Just learned about systemd's
RemoveIPC
setting, which does the same: https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#RemoveIPC=Just mentioning this, because it shows that others need to deal with the same thing.
Hmmm. That's very interesting if only because maybe the code might be portable. There are a bunch of edge cases (how do you make sure only your own ipc objects get removed, etc) that seem hard if we're going to be implementing something from scratch so that's very helpful.
(not saying this is a priority for me personally though; i don't expect this issue to be fixed in the next couple of months without some help from someone outside the lix team)