Skip to content

test: close SQLite integrity-check connection in shared-storage suite - #117

Merged
luocfprime merged 1 commit into
luocfprime:mainfrom
jinfanchris:fix/shared-storage-close-sqlite-connection
Sep 24, 2026
Merged

luocfprime merged 1 commit into
luocfprime:mainfrom
jinfanchris:fix/shared-storage-close-sqlite-connection

Conversation

@jinfanchris

Copy link
Copy Markdown
Collaborator

Summary

_assert_database_integrity() in tests/shared_storage/test_shared_storage.py opens the database with with 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, while TemporaryDirectory removes 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 with OSError: [Errno 39] Directory not empty for the three tests that end with _assert_database_integrity():

  • test_http_task_worker_lifecycle_survives_restart
  • test_concurrent_http_writers_and_workers_are_stable
  • test_shared_socket_daemon_is_idempotent_and_manageable

All assertions in those tests pass; only teardown errors. This PR closes the connection explicitly. It changes test code only.

Reproduction

  • Cluster: NUS SoC Slurm compute node (xcnc1), Python 3.11.14, main @ 08e5e22
  • Mount: nfs4 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 -q

Before the fix, 2 of 2 runs ended with 5 passed, 3 errors. After the fix, 5 of 5 runs ended with 5 passed. The comparison ran on the same node, to rule out stale NFS attribute caching of the test file.

Diagnosis

Just before TemporaryDirectory cleanup, a /proc/*/fd scan showed that the only process holding the case's .db file (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 in database.py, and Database.dispose() releases it correctly: test_auto_profile_pragmas_transactions_and_reopen opens, 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_storage
  • uv run ruff check tests/shared_storage
  • uv run pytest tests/shared_storage (skips as expected without the env var)
  • shared_storage_integration on NFS as above

🤖 Generated with Claude Code

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>
@luocfprime
luocfprime merged commit 68e28b0 into luocfprime:main Sep 24, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants