Skip to content

Introduce programmatic popen and run execution layers with distributed process controllers - #129

Merged
dmitry-lipetsk merged 30 commits into
postgrespro:masterfrom
dmitry-lipetsk:D20260914_001--os_ops
Sep 15, 2026
Merged

dmitry-lipetsk merged 30 commits into
postgrespro:masterfrom
dmitry-lipetsk:D20260914_001--os_ops

Conversation

@dmitry-lipetsk

@dmitry-lipetsk dmitry-lipetsk commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR refactors the core process execution layer in testgres.os_ops to transition from the legacy exec_command to a modern, decoupled abstraction model utilizing popen and run. This layer guarantees cross-platform uniformity, preventing descriptor leaks and handling complex environmental differences (such as standard library variations in Alpine or specific hardware constraints).

Core Enhancements

  1. Uniform Interface Layer (OsProcessController & OsCommandResult)

    • Implemented abstract and runtime process controllers (LocalProcessController, RemoteProcessController) to provide full API symmetry with standard subprocess.Popen.
    • Integrated explicit runtime verification checks (io.IOBase) for all standard I/O pipes, descriptors, and streams.
  2. Robust Multi-stage Remote Handshake Mechanism

    • Redesigned RemoteOperations::popen around a multi-stage POSIX-compliant script wrapper.
    • Uses precise time.monotonic() loops to execute state handshakes via remote transient tracking files (pid_file, rc_file).
    • Eliminates historical network transport 255 exit status side-effects, ensuring exact signal propagation (137 for SIGKILL, 143 for SIGTERM).
  3. Prevention of Deadlocks and Resource Leaks

    • Integrated fully isolated contextual managers (__enter__ / __exit__) across controllers to automate cleanup procedures.
    • Implemented safety-first deterministic __init__ sequences combined with defensive __del__ destructors to force-terminate dangling SSH client pipes and avoid active zombie nodes.
  4. Emergency Configuration Overrides (OsOperationStaticConfig)

    • Introduced a centralized, strict static configuration layer initialized at module-import time to avoid repetitive runtime os.environ overhead.
    • Added the TESTGRES_OS_OPS_CFG__REMOTE_OPS__POPEN__HANDSHAKE_TIMEOUT environment variable option (defaulting to 10.0s, with a valid range up to 4 hours) to prevent unexpected test flakes under high-density infrastructure loads (e.g., Elbrus/e2k compilation farms).
    • Embedded strict type, value boundary validations, and verbose _debug_print diagnostics to prevent silent misconfigurations in CI/CD environments.

Testing Suite Summary

  • Expanded test matrix mapping over multiple runtime scenarios covering complex argument matrices (text, encoding, shell, input, streams).
  • Successfully validated across multi-node execution nodes (including Ubuntu, Alt Linux, Rocky Linux, Astra Linux, and Alpine musl).

What's Next

This PR lays the public contract for user space execution. Internal utilities (e.g., read_binary, mkstemp, remove_file) will be isolated onto private _transport_popen and _transport_run wheels in a follow-up patch to cleanly decouple internal system tasks from user pipelines.

OsOperations::popen runs process and returns a controller object - OsProcessController.

Also
 - ExecTimeoutException is added.
We will use response file to get a result code of user command.
It is used for external configuring of remote_ops__popen__handshake_timeout.
@dmitry-lipetsk
dmitry-lipetsk merged commit 56e414b into postgrespro:master Sep 15, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant