Class: TIMEx::Strategies::Subprocess
- Defined in:
- lib/timex/strategies/subprocess.rb
Overview
Note:
The child inherits all open file descriptors; shared connections can corrupt the parent if reused in the child. Re-open resources in the child or close inherited FDs deliberately.
Runs user code in a forked child and returns the marshalled result to the parent.
Constant Summary collapse
- EMPTY_PAYLOAD =
Message used when the child exits without producing a marshalled result (segfault, OOM, exec, etc.) so the parent can distinguish from a legitimate ‘[:ok, nil]` return.
"the child exited without producing a result"- DEFAULT_MAX_PAYLOAD_BYTES =
Default ceiling on the marshalled child payload. A buggy or malicious block can otherwise drive the parent OOM by streaming arbitrary data through the pipe before the deadline fires.
8 * 1024 * 1024
Instance Method Summary collapse
-
#initialize(kill_after: 0.5, max_payload_bytes: DEFAULT_MAX_PAYLOAD_BYTES) ⇒ Subprocess
constructor
A new instance of Subprocess.
Methods inherited from Base
Methods included from NamedComponent
Constructor Details
#initialize(kill_after: 0.5, max_payload_bytes: DEFAULT_MAX_PAYLOAD_BYTES) ⇒ Subprocess
Returns a new instance of Subprocess.
27 28 29 30 31 32 33 34 |
# File 'lib/timex/strategies/subprocess.rb', line 27 def initialize(kill_after: 0.5, max_payload_bytes: DEFAULT_MAX_PAYLOAD_BYTES) super() raise ArgumentError, "kill_after must be a non-negative Numeric" unless kill_after.is_a?(Numeric) && !kill_after.negative? raise ArgumentError, "max_payload_bytes must be a positive Integer" unless max_payload_bytes.is_a?(Integer) && max_payload_bytes.positive? @kill_after = kill_after @max_payload_bytes = max_payload_bytes end |