LightRAG/tests
BukeLy 204a2535c8 fix: prevent double-release in UnifiedLock.__aexit__ error recovery
Problem:
When UnifiedLock.__aexit__ encountered an exception during async_lock.release(),
the error recovery logic would incorrectly attempt to release async_lock again
because it only checked main_lock_released flag. This could cause:
- Double-release attempts on already-failed locks
- Masking of original exceptions
- Undefined behavior in lock state

Root Cause:
The recovery logic used only main_lock_released to determine whether to attempt
async_lock release, without tracking whether async_lock.release() had already
been attempted and failed.

Fix:
- Added async_lock_released flag to track async_lock release attempts
- Updated recovery logic condition to check both main_lock_released AND
  async_lock_released before attempting async_lock release
- This ensures async_lock.release() is only called once, even if it fails

Testing:
- Added test_aexit_no_double_release_on_async_lock_failure:
  Verifies async_lock.release() is called only once when it fails
- Added test_aexit_recovery_on_main_lock_failure:
  Verifies recovery logic still works when main lock fails
- All 5 UnifiedLock safety tests pass

Impact:
- Eliminates double-release bugs in multiprocess lock scenarios
- Preserves correct error propagation
- Maintains recovery logic for legitimate failure cases

Files Modified:
- lightrag/kg/shared_storage.py: Added async_lock_released tracking
- tests/test_unified_lock_safety.py: Added 2 new tests (5 total now pass)
2025-11-23 16:34:08 +08:00
..
conftest.py Add GitHub CI workflow and test markers for offline/integration tests 2025-11-18 11:36:10 +08:00
README_WORKSPACE_ISOLATION_TESTS.md Fix linting 2025-11-18 08:07:54 +08:00
test_aquery_data_endpoint.py Add GitHub CI workflow and test markers for offline/integration tests 2025-11-18 11:36:10 +08:00
test_base_storage_integrity.py style: fix lint errors (trailing whitespace and formatting) 2025-11-20 01:41:23 +08:00
test_curl_aquery_data.sh Fix linting 2025-10-06 04:57:11 +08:00
test_dimension_mismatch.py fix: prevent race conditions and cross-workspace data leakage in migration 2025-11-23 16:09:59 +08:00
test_e2e_multi_instance.py test: add E2E test for workspace migration isolation 2025-11-23 16:27:05 +08:00
test_embedding_func.py style: fix lint errors (trailing whitespace and formatting) 2025-11-20 01:41:23 +08:00
test_graph_storage.py Add GitHub CI workflow and test markers for offline/integration tests 2025-11-18 11:36:10 +08:00
test_lightrag_ollama_chat.py Rename test classes to prevent warning from pytest 2025-11-18 13:33:05 +08:00
test_no_model_suffix_safety.py fix: prevent vector dimension mismatch crashes and data loss on no-suffix restarts 2025-11-23 15:44:07 +08:00
test_postgres_migration.py fix: prevent race conditions and cross-workspace data leakage in migration 2025-11-23 16:09:59 +08:00
test_postgres_retry_integration.py Add GitHub CI workflow and test markers for offline/integration tests 2025-11-18 11:36:10 +08:00
test_qdrant_migration.py feat: implement dimension compatibility checks for PostgreSQL and Qdrant migrations 2025-11-20 12:22:13 +08:00
test_unified_lock_safety.py fix: prevent double-release in UnifiedLock.__aexit__ error recovery 2025-11-23 16:34:08 +08:00
test_workspace_isolation.py Fix test to use default workspace parameter behavior 2025-11-18 11:51:17 +08:00
test_workspace_migration_isolation.py fix: prevent race conditions and cross-workspace data leakage in migration 2025-11-23 16:09:59 +08:00
test_write_json_optimization.py Add GitHub CI workflow and test markers for offline/integration tests 2025-11-18 11:36:10 +08:00