Add isolated context mode: CPython in a child OS process - #72
Merged
Conversation
benoitc
force-pushed
the
isolated-mode
branch
5 times, most recently
from
August 29, 2026 09:09
6c42d5a to
a2108b8
Compare
A mode where Python code cannot take the node down or run forever: one child process per context over a Unix socket, signals with SIGKILL as backstop, rlimits and cgroups, restart on crash. Same public API; the context process is a gen_statem serving one caller at a time. Validated on macOS and FreeBSD. Version 4.2.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
mode => isolated: the Python interpreter of a context runs in a child OS process.workerandowngilare unchanged.The goal is a mode where Python code cannot take the node down or run forever, without giving up the C extension ecosystem. The embedded interpreter cannot offer that: an interrupt only lands at the next bytecode, memory cannot be capped soundly, and a segfault in any extension kills the VM. A child process gets all of it from the OS: a signal lands wherever the child is,
SIGKILLis the backstop, rlimits and cgroups bound it, and a crash costs one child, which is restarted within a budget.The child is driven over a Unix socket with the framing of the existing callback pipe, and needs no native code on the Python side, only a small ETF codec with the NIF's type mapping. The public API is the same; where the child cannot match an embedded behaviour it fails loudly instead of diverging. The context process is a
gen_statemthat serves one caller at a time and lets callbacks re-enter, and a timeout cancels only its own request. On macOS the child enforces the memory limit itself, since the kernel ignoresRLIMIT_AS; thecgroupoption is refused outside Linux. Listen sockets are handed to children over the control socket, so the worker loop shape works out of process.The cost is about 10 us per call over
workermode, one process per context, and payloads copied through the socket. Shared memory througherlang-iommapis left for a follow-up.Validated on macOS and FreeBSD. Guide:
docs/isolated.md. Version 4.2.0.