Repository navigation
Close the pgvector connection pool before interpreter shutdown - #162
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Every CLI command that touched the database (
ragbot db status,ragbot index, ...) ended with this on Python 3.14:The cached backend kept its
psycopg_pool.ConnectionPoolalive until interpreter finalization. The pool's__del__then tried to join its worker threads, which Python 3.14 refuses at that point. Ragbot moved to 3.14 in #158.Change
PgvectorBackend._ensure_poolregisters anatexithook that closes the pool. Exit hooks run before finalization, while threads can still be joined. The hook holds a weak reference, so it never keeps a discarded backend's pool, and its connections, open.PgvectorBackend.close()closes the pool and is idempotent.VectorStore.close()is a no-op default for backends that hold no connections.reset_vector_store()closes the cached backend before dropping it, so tests that reset no longer leave pools open.Verification
ragbot db statusagainst a live database: the traceback appears onmainand not with this change.close()idempotence, andreset_vector_store()closing the backend.get_vector_store()'s cache keeps it in the CLI, and the test asserts stderr is clean. It fails onmainwithPythonFinalizationErrorand passes here.make test-fastis green. With a throwaway pgvector 18 database (app and migration roles split, as in compose), the full suite passes, including the live tests.🤖 Generated with Claude Code