Fix: Add Comprehensive Retry Mechanism for Neo4j Storage Operations#2417
Merged
danielaskdd merged 3 commits intoHKUDS:mainfrom Nov 24, 2025
Merged
Fix: Add Comprehensive Retry Mechanism for Neo4j Storage Operations#2417danielaskdd merged 3 commits intoHKUDS:mainfrom
danielaskdd merged 3 commits intoHKUDS:mainfrom
Conversation
… storage • Define READ_RETRY_EXCEPTIONS constant • Create reusable READ_RETRY decorator • Replace 11 duplicate retry decorators • Improve code maintainability • Add missing retry to edge_degrees_batch
Collaborator
Author
|
@codex review |
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.
🐛 Fix: Add Comprehensive Retry Mechanism for Neo4j Storage Operations
Problem
Users were experiencing
AttributeError: 'NoneType' object has no attribute 'send'errors during document processing with Neo4j storage backend. This error occurred in the merging stage when the connection pool encountered transient network issues or connection lifecycles, causing operations to fail with NoneType objects attempting to call the.send()method.Error Stack Trace:
Solution
Implemented comprehensive retry logic using the tenacity library for all critical Neo4j database operations. The retry mechanism handles transient failures gracefully by automatically retrying failed operations with exponential backoff.
Changes Made
Modified Files
lightrag/kg/neo4j_impl.py- Added retry decorators to 15 critical database operationsFunctions Enhanced with Retry Logic
Read Operations (10 functions) - Retry on connection errors including
AttributeError:has_node- Check node existencehas_edge- Check edge existenceget_node- Get single nodeget_nodes_batch- Batch get nodesnode_degree- Get node degreenode_degrees_batch- Batch get node degreesget_edge- Get single edgeget_edges_batch- Batch get edgesget_node_edges- Get all edges for a nodeget_nodes_edges_batch- Batch get node edgesWrite Operations (5 functions) - Retry on write-specific errors:
upsert_node- Insert/update nodeupsert_edge- Insert/update edgedelete_node- Delete noderemove_nodes- Batch delete nodesremove_edges- Batch delete edgesRetry Configuration
Read Operations:
ServiceUnavailable,TransientError,SessionExpired,ConnectionResetError,OSError,AttributeErrorWrite Operations:
WriteServiceUnavailable,ClientErrorBenefits
✅ Improved Reliability - Automatically recovers from transient connection pool and network issues
✅ Production Ready - Handles connection lifecycle problems gracefully
✅ Zero Breaking Changes - Transparent retry logic with no API changes
✅ Better User Experience - Document processing continues successfully despite temporary failures
✅ Comprehensive Coverage - All critical database operations protected
Testing Recommendations