Skip to content

[packaging] documentdb-setup, reset and package removal report success that isn't true #760

Open

Description

@guanzhousongmicrosoft

Several day-2 paths in the native install exit 0 while the system is not in the state they report. Mostly non-systemd hosts. Related: #727, #732.

Items

  • documentdb-setup: pg_ctl restart path omits -l, so the new postmaster keeps setup's stdout and hangs piped callers
  • documentdb-setup (non-systemd): scoped --restore and --status ignore the recorded gateway PID, so success/health can be false
  • Reset and package removal report success while PostgreSQL or the gateway is still running (non-systemd)
  • documentdb-setup re-run resets DOCUMENTDB_LISTEN_ADDR to a wildcard bind and never updates documentdb_core
  • documentdb-setup configures a major with no documentdb-N package; apt autoremove can then remove a running install
  • documentdb-gateway --check reports OK when pg_hba/pg_ident changes haven't been reloaded

1. documentdb-setup: pg_ctl restart path omits -l, so the new postmaster keeps setup's stdout and hangs piped callers

On non-systemd hosts, when PostgreSQL is already running and the config changed (e.g. re-running with --restore, or DOCUMENTDB_TOAST_COMPRESSION changed), documentdb-setup restarts it with:

documentdb-local/scripts/documentdb-setup.sh:3078
run_as_user documentdb-local "${PG_CTL}" -D "${DATA_DIR}" -w restart      # no -l

while the start path at :3084 passes -l "${DATA_DIR}/pglog.log". Without -l the new postmaster inherits setup's stdout/stderr. Setup prints SUCCESS: DocumentDB is ready and exits, but the pipe stays open, so any caller reading it (| tee, | cat, $(...), CI log capture) blocks until timeout. A minimal pg_ctl restart | cat without -l times out; with -l it returns.

Side effects: PG log lines leak into the caller's stdout/file instead of pglog.log, which the setup hint at :3804 points users to.

Related: the gateway fallback launch (:3602) uses nohup ... & without setsid, so it stays in the caller's process group. When the hung caller is Ctrl-C'd or hit by a CI timeout SIGTERM, the gateway gets the signal too and the service ends up down after a success message.

Fix: add -l "${DATA_DIR}/pglog.log" to the restart at :3078, and consider setsid for the gateway launch (check the pidfile/exe-match logic still holds). A regression test could run the restart path with stdout piped to cat under a timeout.

2. documentdb-setup (non-systemd): scoped --restore and --status ignore the recorded gateway PID, so success/health can be false

Without systemd, documentdb-setup writes a per-port record at gateway launch (nohup_gateway_pid_for_port) but several paths ignore it. Static read of documentdb-local/scripts/documentdb-setup.sh on main:

  1. Scoped --restore --pg-version N (:4852) skips the nohup sweep, deletes setup.conf, then prints "Restore complete" and exits 0 (:4884). The gateway keeps serving and can no longer be located via state. The recorded port isn't read first.
  2. --status (:4240) reports active (nohup; no systemd) whenever anything listens on the port, with no PID/exe check, and exits 0 if mode is configured. A foreign listener reads as healthy.
  3. --listen-port change (start_gateway, :3433 onward) only inspects the new port; the previously persisted port's gateway keeps running. The restore comment at :4796 describes this exact two-gateway outcome.
  4. When find_listener_pid returns the "1" placeholder (:543-585) and no record exists, setup dies with die_unknown_listener_owner even with lsof/ss installed; there's no cmdline fallback.

Fix sketch: in scoped restore, read the major's GATEWAY_PORT, stop the recorded PID, and die non-zero if it can't be stopped. In --status, require a live recorded PID with a matching exe. In start_gateway, stop the old persisted port's recorded gateway on change.

Scope decisions:

  • Sub-item 3 under --no-enable: setup leaves the old port's gateway running and warns with the port. --no-enable means "don't change the gateway's running state"; stopping it would leave nothing listening on either port.
  • Sub-item 4 is deferred to its own change. A cmdline fallback can't tell which major owns the port on a multi-major host (every gateway has the same command line except its config path), so it risks stopping another major's gateway. A correct fix needs config-path matching. Until then setup keeps failing with a clear error rather than guessing.

Related: #727.

3. Reset and package removal report success while PostgreSQL or the gateway is still running (non-systemd)

On a host without systemd, three teardown paths exit 0 while a postmaster or gateway keeps running. Related to #727, which covers only documentdb-setup --restore.

  1. documentdb-local-reset --confirm-destroy: documentdb-local/scripts/documentdb-local-reset.sh:232-250 only runs pg_ctl stop and the live-postmaster check when ${data_dir}/postmaster.pid exists. If the data dir is already gone, or the major was never installed, both are skipped. The [[ -d ]]-guarded removals (253-285) become no-ops and line 294 prints "completely reset" regardless. Repro: documentdb-setup, rm -rf /var/lib/documentdb-local/18/data, then reset prints success and exits 0 while the postgres process and port 9718 are still up. A never-installed major also reports success.

  2. DEB prerm for documentdb-N (packaging/standalone/build-standalone-deb.sh:236-250) and the gateway prerm (documentdb-local/maintainer-scripts/gateway/prerm:24-33) only stop things when systemd is present. The RPM %preun in packaging/rpm/spec/documentdb-gateway.spec:146-162 has the same gate. apt purge therefore leaves the nohup gateway and postgres serving from deleted binaries and config.

  3. autoremove can drop documentdb-gateway while it keeps serving, same cause.

Suggested fix: reset locates the postmaster without relying on PGDATA (the pid file, then pgrep/port), stops it, verifies nothing is left, and prints a distinct message when there is nothing to reset. On non-systemd hosts, prerm stops the processes it started (fast, then immediate shutdown) and warns if one survives.

Scope decision: removal never refuses. That matches the systemd branch of the same scripts (systemctl stop ... || true) and Debian's postgresql packages. A process that survives an immediate shutdown is usually mid-checkpoint, where blocking apt/dnf and telling the operator to kill it is worse than a warning.

4. documentdb-setup re-run resets DOCUMENTDB_LISTEN_ADDR to a wildcard bind and never updates documentdb_core

Two silent day-2 problems in documentdb-setup re-runs.

1. Re-run overwrites a restricted bind address. default_gateway_settings_from_persisted_state (documentdb-local/scripts/documentdb-setup.sh:2243) restores only the port and TLS keys. Then documentdb-setup.sh:2364 always passes --listen-addr ":${GATEWAY_PORT}", and write_gateway_env_fragment (documentdb-register-gateway.sh:1230-1244) rewrites the managed block via rewrite_with_managed_block (documentdb-tools-lib.sh:371), which appends the new block last. So DOCUMENTDB_LISTEN_ADDR=127.0.0.1:10260 becomes :10260 (all interfaces), exit 0, no warning. --status (documentdb-setup.sh:4252-4266) prints only the port, so the change is invisible.

2. documentdb_core is never updated. The wizard runs ALTER EXTENSION documentdb UPDATE (:3235) and ALTER EXTENSION documentdb_extended_rum UPDATE (:3242), but not documentdb_core. After a package upgrade plus re-run, documentdb moves to the new version while documentdb_core stays on the old catalog version. --status shows no extension versions either.

Suggested fix

  • Restore the persisted DOCUMENTDB_LISTEN_ADDR host the same way the port/TLS are restored, with a "Keeping gateway bind address ..." log line.
  • Run ALTER EXTENSION documentdb_core UPDATE before documentdb (same transaction).
  • Print the bind address and installed documentdb_core/documentdb/documentdb_extended_rum versions in --status.
  • Add tests for both in documentdb_local_tests/test_documentdb_setup.py.

Related: #732 (installer day-2 diagnostics).

5. documentdb-setup configures a major with no documentdb-N package; apt autoremove can then remove a running install

documentdb-setup --pg-version N only checks that PG binaries and documentdb.control exist (documentdb-local/scripts/documentdb-setup.sh:1532, :2036); the only major gate is >= 16 (:2591). It never checks that documentdb-N is installed. Since documentdb-common is held only by documentdb-N's Depends (packaging/standalone/build-standalone-deb.sh), it stays auto-installed for another major only.

Repro (Debian/Ubuntu):

apt-get install postgresql-17-documentdb documentdb-18
documentdb-setup ... --pg-version 17      # succeeds, gateway on 10260
apt-get purge --autoremove documentdb-18 postgresql-18-documentdb

documentdb-common, gateway and tools get autoremoved. The PG17 gateway keeps running from a deleted binary, and documentdb-setup / documentdb-local-reset are gone.

Also: build-common-deb.sh:159 has an unversioned Replaces: documentdb-16, documentdb-17, documentdb-18 with no Breaks, so apt offers documentdb-common as a substitute for a missing documentdb-N. The comment above it says the pre-split package never shipped.

Suggested fix:

  • In setup, require documentdb-<major> (dpkg-query / rpm -q) when documentdb-common is package-managed; die or warn.
  • Drop that Replaces, or pair it with a Breaks.
  • Optionally apt-mark manual documentdb-common at setup.

6. documentdb-gateway --check reports OK when pg_hba/pg_ident changes haven't been reloaded

documentdb-gateway --check can print check OK and exit 0 while every client request would fail peer authentication.

Why: run_check (pg_documentdb_gw/documentdb_gateway/src/check.rs:27-62) calls create_connection_pool_manager, whose validate_startup_pools (pool_manager.rs:387-396) only touches the SystemRequests and PreAuthRequests pools. Those connect as postgres_system_user (pool_manager.rs:332-345), i.e. the URL-file role, which works with plain same-name peer auth before any reload. check.rs then queries pg_extension on that same system pool.

Client requests use a different path: allocate_data_pool (auth.rs:576, auth.rs:770, context/connection.rs:245-254) connects as the authenticated user, relying on the managed peer map=documentdb-gateway-map rule written by documentdb-local/scripts/documentdb-register-gateway.sh:420. That rule is only active after a PostgreSQL reload, which the script just prints as a remaining step (:695, :742). --check never exercises it.

Repro: run documentdb-register-gateway, skip the reload, run documentdb-gateway --check (OK), then connect with a client (peer auth failure).

packaging/gateway/packaging-design.md:166 claims a green --check "strongly implies a successful service start"; not true here. test-gateway-install-entrypoint.sh only checks the happy path after reload.

Fix idea: after the system-pool query, open a throwaway data-pool connection as a role covered by the managed hba/ident entries (e.g. a member of documentdb_admin_role) and run SELECT 1. On failure, print the role and hint at systemctl reload postgresql@<N>-<cluster>. Add a negative test: register, no reload, --check must fail; reload, must pass.

Activity

  1. added this to the 1.0-RC2 milestone on Oct 5, 2026
  2. guanzhousongmicrosoft commented on Oct 5, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    Plan: items 1-4 go in 1.0-RC2, together with #727. Items 5 and 6 go in 1.0.

  3. added
    1.0-blocker
    on Oct 6, 2026
  4. guanzhousongmicrosoft commented on Oct 6, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    1.0 blockers: items 1-4. The fix is in review. Items 5 and 6 don't block 1.0.

  5. documentdb-triage-tool commented on Oct 28, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 22 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  6. documentdb-triage-tool commented on Nov 11, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  7. guanzhousongmicrosoft commented on Nov 23, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    Items 1–5 are fixed on main (1e882d8, eca4171, b566aa3), with sub-item 2.4 deferred. Item 6, documentdb-gateway --check passing while client-pool peer auth would still fail, is still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

1.0-blockerbugdocumentdb-1.0packaging

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions