Skip to content

Add detached lifecycle mode for persistent clusters#29

Open
m3ridian-zero wants to merge 1 commit into
leinelissen:mainfrom
m3ridian-zero:lifecycle-mode
Open

Add detached lifecycle mode for persistent clusters#29
m3ridian-zero wants to merge 1 commit into
leinelissen:mainfrom
m3ridian-zero:lifecycle-mode

Conversation

@m3ridian-zero

Copy link
Copy Markdown

Summary

Refs #28.

Adds an opt-in lifecycle mode for callers that need a persistent embedded Postgres cluster to outlive the process that started it.

  • adds lifecycleMode: 'managed' | 'detached'
  • keeps managed as the default so existing process-exit cleanup behavior is preserved
  • excludes detached instances from the module-level exit hook
  • starts detached clusters outside the parent terminal/process lifecycle
    • Windows: CreateProcessW with CREATE_NO_WINDOW, tracking the postmaster PID for explicit stop()
    • POSIX: detached spawn with unref'd process/stdio handles
  • waits for detached startup by polling Postgres with SELECT 1
  • keeps explicit stop() supported for detached clusters
  • retries data-directory removal to avoid transient Windows handle-release races
  • documents the new option and adds a detached integration test

Verification

  • npx -p node@20 node node_modules/lerna/cli.js run build
  • npx -p node@20 npm run lint from the embedded-postgres package
  • npx -p node@20 npm test -- tests/index.test.ts -t "detached cluster"
  • npx -p node@20 npm test -- tests/index.test.ts -t "should be able to start and stop a cluster"

Note: the full Windows package test file still has an unrelated pre-existing permission-bit assertion for .exe files; I left that behavior unchanged and verified the PR-specific detached path plus the managed default start/stop path.

Add an opt-in lifecycleMode option so callers can start Postgres isolated from parent process shutdown and terminal signals while preserving the managed default behavior.

Refs: leinelissen#28

Constraint: Preserve current managed lifecycle by default

Scope-risk: moderate

Not-tested: Detached integration test blocked locally because binary download requires tar plus xz/zstd utilities

Confidence: medium
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