Skip to content

testdb.throwaway_db() leaks databases: 23 selector_test_* still on the box #32

Description

@JacobStephens2

Found while scoping orchestration #175.

selector/testdb.py creates a per-test database and drops it in a finally:. The drop is not reliably happening: 23 selector_test_<hex> databases were on the local Postgres alongside selector, counted 2026-08-26 with

psql -d postgres -tAc "SELECT count(*) FROM pg_database WHERE datname LIKE 'selector\_test\_%'"

Why it matters beyond tidiness: the same module is the intended builder for selector_staging, and "the throwaway database goes away" is an assumption that work would otherwise inherit. Better to know the drop path is unreliable before something depends on it.

Likely causes worth checking in order:

  1. _drop() raising because a session is still attached - the with psycopg.connect(dsn, ...) block inside throwaway_db() holds a connection to the database being dropped - and the exception being swallowed or aborting the run.
  2. Interrupted or crashed test runs never reaching the finally: at all: pytest killed, a SIGKILL, or a hung NOTIFY listener.

Two things to land:

• Make the drop robust: DROP DATABASE ... WITH (FORCE) (Postgres 13+, and this box is on 16), or terminate backends on the target first.
• A cleanup path for the ones already there, and something that makes the leak visible rather than silent - the count is only discoverable by going and looking.


Originally filed as Educational-Travel-Adventures/orchestration#178.
Note: Core implementation landed in orchestration#324 and carried into Tracewake at selector/tests/test_testdb.py.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions