Skip to content

Bug: Plugin process never exits after Tabularis quits if an RPC is in flight #155

Closed

Description

@psaus

Plugin version

v1.0.0-rc.9

Tabularis app version

v0.28.0

Operating system

macOS 26.6.2

What happened?

Summary

When Tabularis quits while an RPC is still in flight (e.g. a query or connection attempt that is not getting a response), the postgresql-plugin process never exits. It is reparented to launchd (PPID 1) and keeps running — together with any database connections it holds — until it is killed manually.

Environment

  • Plugin: v1.0.0-rc.9
  • Tabularis: v0.28.0
  • macOS (darwin arm64)
  • Connection goes through PgBouncer

What I observed

After quitting Tabularis, postgresql-plugin processes were still running with PPID 1. In one case there were two of them, left over from two separate Tabularis sessions.

Root cause

The plugin only exits after stdin reaches EOF and every worker has finished its current request:

// src/main.rs
run_reader(req_tx).await;          // returns on stdin EOF
let _ = shutdown_tx.send(true);
for handle in worker_handles {
    let _ = handle.await;          // no upper bound
}

None of the awaits a worker can be blocked on has a time limit: there is no connect_timeout, no pool wait timeout, and no statement timeout. The only timeout in src/client.rs is the one for the startup script (STARTUP_SCRIPT_TIMEOUT_MS). So if a request is stuck — for example the server or a pooler accepted the TCP connection but never answers — the plugin waits for it forever after stdin closes.

Steps to reproduce

  1. Start a TCP listener that accepts connections but never responds:
    import socket
    s = socket.socket(); s.bind(("127.0.0.1", 54329)); s.listen(8)
    conns = []
    while True:
        c, _ = s.accept(); conns.append(c)
  2. Send one request to the plugin, then close stdin (this simulates Tabularis quitting):
    ( echo '{"jsonrpc":"2.0","id":1,"method":"test_connection","params":{"params":{"driver":"postgres","host":"127.0.0.1","port":54329,"database":"x","username":"u","password":"p","ssl_mode":"disable"}}}'
      sleep 1 ) | ./postgresql-plugin
  3. Expected: the plugin exits shortly after stdin closes.
    Actual: the plugin is still running more than 10 seconds after stdin was closed, and nothing in the code would stop it.

As a control, printf '' | ./postgresql-plugin exits immediately, so a plain EOF is handled correctly; the problem only appears when a request is in flight.

Error message, if any


Activity

  1. added
    bug
    on Oct 15, 2026
  2. self-assigned this
    on Oct 15, 2026
  3. aesslinger commented on Oct 15, 2026

    @aesslinger
    Collaborator

    Thanks for the thorough report — the repro steps and root-cause analysis were spot on and made this fast to pin down.

    I've confirmed the bug against the current build: a worker blocked on a connect that never completes (your hanging-listener case) wedges the process past stdin EOF, because main.rs awaited every worker with no upper bound after EOF and nothing in the connect/query path has a time limit. (echo test_connection …; sleep 1) | ./postgresql-plugin hung past 15s; printf '' | ./postgresql-plugin exited instantly — exactly your control case.

    A fix is in the works in #156: after stdin EOF, drain in-flight RPCs for at most 5s (SHUTDOWN_GRACE), then force-cancel any worker still blocked via handle.abort() — which cancels the stuck future and drops the held DB connection, closing the socket server-side rather than leaking it. I verified it against your repro (exits ~6s after stdin closes instead of hanging) with no regressions across the live-database test suite.

    One thing worth noting on your connect_timeout suggestion: tokio-postgres's connect_timeout bounds only the socket-level connect, not the startup handshake, so it wouldn't actually bound your hanging-listener case (the TCP connect succeeds instantly; the handshake read is what blocks). The shutdown deadline is what covers it. Pool-config timeouts are still a reasonable complementary fail-fast for genuinely dead hosts, so I'll look at that as a follow-up.

    Will update here once #156 lands and cuts a release.

  4. aesslinger commented on Oct 15, 2026

    @aesslinger
    Collaborator

    An update on the fix now that the pre-handoff review has run across the full diff (#156).

    Headline: the ensemble review caught a real defect in the regression test — the "hanging listener" test helper was dropping the accepted TCP connection immediately instead of holding it open, so the primary regression test passed on unfixed code and never actually exercised the SHUTDOWN_GRACE abort path (it was a false guard). That's been fixed (streams are now collected and held open) and verified the hard way: the test fails on unfixed code (hangs past its 20s deadline with the exact #155 message) and passes on fixed (~5.4s exit). Four independent reviewers (boundary, docs-vs-code-drift, correctness, and /code-review) all flagged the same issue — good corroboration.

    Production code (the actual fix in src/main.rs): clean across all 11 review dimensions. The fix's central claim — that handle.abort() cancels the stuck worker and drops the held deadpool::Object (or in-flight pool.get() future), releasing the DB socket — was verified against real tokio 1.53.2 and deadpool 0.13.1/0.14.2 source. No findings on the production code.

    One known limitation worth flagging for completeness: the regression test proves the process exits on fixed code but does not prove that abort() (vs. simply dropping the handle / detaching) is what closes the DB socket server-side. The distinction matters — abort() drops the held connection immediately (prompt server-side cleanup), while drop(handle) would let the task live until runtime teardown, which still closes the socket but only when the process fully exits. Both let the test pass because both let the process exit. Verifying the server-side socket closure would require a live pooler with connection-count inspection, which is impractical for a DB-free regression test. The abort() is still the correct choice (prompt cleanup, not deferred-to-exit), and the code comment documents why — but the test guards process-exit, not socket-closure-timing.

    CI is green on the critical jobs (Test, Live PostgreSQL integration, Markdown lint, manifest validation). The PR is ready for merge once the last CI job (security audit, a dep scan) finishes.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions