Fix Windows embedded Postgres command completion and owned teardown - #2544
Open
darionco wants to merge 2 commits into
Open
Fix Windows embedded Postgres command completion and owned teardown#2544darionco wants to merge 2 commits into
darionco wants to merge 2 commits into
Conversation
On Windows, runLocalCommand resolved on the child 'close' event; pg_ctl start daemonizes Postgres, which inherits the stdio pipe handles and keeps them open, so 'close' never fires at the pg_ctl boundary even after the server is ready — blocking embedded-Postgres provisioning. Resolve on 'exit' (resuming streams without waiting for EOF), and add owned-cluster teardown (record dataDir + postmaster PID after readiness, pg_ctl -m fast -w stop, wait for process + listener to close, wired through DBOS lifecycle shutdown). Processes that attach to an already-running cluster do not stop it.
Author
|
Tracking issue for this implementation: #2547. Addressing reviewer feedback:
Will loop on any further reviewer feedback until there is none addressable and CI is green. |
…p port-reachability fallback Once the owned postmaster PID is gone, clusterStillRunning no longer consults TCP on 127.0.0.1:5439, so an unrelated listener can no longer keep DBOS shutdown pending indefinitely. Wait now returns false immediately when the recorded postmaster.pid no longer matches the captured PID. Refs bastani-inc#2547
Author
|
Loop complete — no addressable reviewer feedback remaining and CI is green.
Ready for review/merge. |
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.
Fix Windows embedded Postgres command completion and owned teardown
Summary
On Windows,
runLocalCommandcaptured stdout/stderr with piped handles and resolved on the child'scloseevent.pg_ctl startdaemonizes Postgres; inherited pipe handles remain open in the Postgres process, soclosedoes not fire at thepg_ctlprocess boundary even after the server is ready. This blocks embedded-Postgres provisioning.This patch resolves local commands on the child
exitevent, resumes both streams without waiting for EOF, and preserves bounded stdout/stderr tails, exit-code semantics, and error handling.It also makes embedded Postgres teardown explicit for clusters started by the current process: record the data directory and postmaster PID after readiness, stop with
pg_ctl -m fast -w, wait for the captured process and TCP listener to disappear, and wire provider shutdown through DBOS lifecycle shutdown. Processes that attach to an already-running cluster do not claim ownership or stop it.Scope
packages/workflows/src/durable/local-command.ts: general inherited-stdio completion fix (close→exit).packages/workflows/src/durable/dbos-embedded-postgres.ts: process-local cluster ownership and graceful stop/wait.packages/workflows/src/durable/dbos-local-postgres.ts: embedded-provider shutdown hook.packages/workflows/src/durable/dbos-lifecycle.ts: invoke local-provider shutdown after DBOS shutdown.Evidence — achieved
pg_ctlexits at its process boundary while the daemonized Postgres child retains the stdio pipes;closeis delayed until the daemon exits, whileexitfires whenpg_ctlexits.32311811708, Windows proof job96256153352: embedded proof passed and job cleanup reported zero orphan Postgres processes.32311811708, Windows proof job96258157451: embedded proof passed in 51.1s and job cleanup reported zero orphan Postgres processes.Tradeoff disclosure
Resolving on
exitand resuming the streams avoids the Windows inherited-handle deadlock, but a trailing diagnostic chunk emitted between the finaldataevent andexitmay not be captured. This is intentional: waiting forcloseis the failure mode being fixed, and callers retain bounded diagnostics already received before process exit.Regression-test disclosure
The end-to-end Windows embedded-Postgres proof currently lives in the downstream weigent repository, where it exercises the carried patch and verifies provisioning, durable execution, shutdown, and force-disabled removal. We can add an Atomic-side regression test in the upstream harness if preferred.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Greptile Summary
Embedded Postgres shutdown now follows the postmaster PID recorded by the session that started it. A focused check confirmed that shutdown completes when that PID no longer matches
postmaster.pid, even if an unrelated process is listening on port 5439.Confidence Score: 5/5
No blocking failure remains.
The shared-port teardown path was exercised with a live unrelated listener and a changed postmaster PID; the current implementation completed immediately rather than waiting for the port to close.
What T-Rex did
Reviews (2): Last reviewed commit: "Address greptile P1: gate cluster-shutdo..." | Re-trigger Greptile