test: close SQLite integrity-check connection in shared-storage suite - #117
Merged
luocfprime merged 1 commit intoSep 24, 2026
Conversation
sqlite3.Connection's context manager only commits or rolls back; it does not close the connection. The leaked read-only handle kept the database open while TemporaryDirectory removed the case directory. On NFS the client silly-renames the still-open file to .nfsXXXX, so teardown failed with 'Directory not empty' for the three tests that end with _assert_database_integrity(). Co-Authored-By: Claude Opus 5.5 (1M context) <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.
Summary
_assert_database_integrity()intests/shared_storage/test_shared_storage.pyopens the database withwith sqlite3.connect(...) as connection:.sqlite3.Connection's context manager only commits or rolls back; it does not close the connection. The read-only handle therefore stays open until garbage collection, whileTemporaryDirectoryremoves the case directory.On a local filesystem that is harmless. On NFS, the client silly-renames the still-open file to
.nfsXXXX, so teardown fails withOSError: [Errno 39] Directory not emptyfor the three tests that end with_assert_database_integrity():test_http_task_worker_lifecycle_survives_restarttest_concurrent_http_writers_and_workers_are_stabletest_shared_socket_daemon_is_idempotent_and_manageableAll assertions in those tests pass; only teardown errors. This PR closes the connection explicitly. It changes test code only.
Reproduction
xcnc1), Python 3.11.14,main@08e5e22nfs4 rw,vers=4.2,rsize=1048576,wsize=1048576,hard,proto=tcp(StorPool-backed NFS server)LABTASKER_SHARED_STORAGE_TEST_DIR=$HOME/labtasker-nfs-test \ uv run pytest -m shared_storage_integration tests/shared_storage -qBefore the fix, 2 of 2 runs ended with
5 passed, 3 errors. After the fix, 5 of 5 runs ended with5 passed. The comparison ran on the same node, to rule out stale NFS attribute caching of the test file.Diagnosis
Just before
TemporaryDirectorycleanup, a/proc/*/fdscan showed that the only process holding the case's.dbfile (lifecycle.db,concurrency.db,daemon-root/server.db) was the pytest process itself. The Labtasker Server subprocess or daemon had already exited and held nothing. Production code opens SQLite only through SQLAlchemy indatabase.py, andDatabase.dispose()releases it correctly:test_auto_profile_pragmas_transactions_and_reopenopens, disposes and reopens on NFS and leaves nothing behind. So this is a test-helper leak, not a Server defect.Checks
uv run ruff format --check tests/shared_storageuv run ruff check tests/shared_storageuv run pytest tests/shared_storage(skips as expected without the env var)shared_storage_integrationon NFS as above🤖 Generated with Claude Code