Merge pull request #1924 from danielaskdd/neo4j-connection-lifetime

Refact:Enhanced Neo4j Connection Lifecycle Management
This commit is contained in:
Daniel.y 2025-08-08 01:16:42 +08:00 committed by GitHub
commit 2f289f6e25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 1 deletions

View file

@ -2,6 +2,13 @@
uri = neo4j+s://xxxxxxxx.databases.neo4j.io
username = neo4j
password = your-password
connection_pool_size = 100
connection_timeout = 30.0
connection_acquisition_timeout = 30.0
max_transaction_retry_time = 30.0
max_connection_lifetime = 300.0
liveness_check_timeout = 30.0
keep_alive = true
[mongodb]
uri = mongodb+srv://name:password@your-cluster-address

View file

@ -248,7 +248,10 @@ NEO4J_PASSWORD='your_password'
NEO4J_MAX_CONNECTION_POOL_SIZE=100
NEO4J_CONNECTION_TIMEOUT=30
NEO4J_CONNECTION_ACQUISITION_TIMEOUT=30
MAX_TRANSACTION_RETRY_TIME=30
NEO4J_MAX_TRANSACTION_RETRY_TIME=30
NEO4J_MAX_CONNECTION_LIFETIME=300
NEO4J_LIVENESS_CHECK_TIMEOUT=30
NEO4J_KEEP_ALIVE=true
# NEO4J_WORKSPACE=forced_workspace_name
### MongoDB Configuration

View file

@ -98,6 +98,22 @@ class Neo4JStorage(BaseGraphStorage):
config.get("neo4j", "max_transaction_retry_time", fallback=30.0),
),
)
MAX_CONNECTION_LIFETIME = float(
os.environ.get(
"NEO4J_MAX_CONNECTION_LIFETIME",
config.get("neo4j", "max_connection_lifetime", fallback=300.0),
),
)
LIVENESS_CHECK_TIMEOUT = float(
os.environ.get(
"NEO4J_LIVENESS_CHECK_TIMEOUT",
config.get("neo4j", "liveness_check_timeout", fallback=30.0),
),
)
KEEP_ALIVE = os.environ.get(
"NEO4J_KEEP_ALIVE",
config.get("neo4j", "keep_alive", fallback="true"),
).lower() in ("true", "1", "yes", "on")
DATABASE = os.environ.get(
"NEO4J_DATABASE", re.sub(r"[^a-zA-Z0-9-]", "-", self.namespace)
)
@ -109,6 +125,9 @@ class Neo4JStorage(BaseGraphStorage):
connection_timeout=CONNECTION_TIMEOUT,
connection_acquisition_timeout=CONNECTION_ACQUISITION_TIMEOUT,
max_transaction_retry_time=MAX_TRANSACTION_RETRY_TIME,
max_connection_lifetime=MAX_CONNECTION_LIFETIME,
liveness_check_timeout=LIVENESS_CHECK_TIMEOUT,
keep_alive=KEEP_ALIVE,
)
# Try to connect to the database and create it if it doesn't exist
@ -801,6 +820,9 @@ class Neo4JStorage(BaseGraphStorage):
neo4jExceptions.TransientError,
neo4jExceptions.WriteServiceUnavailable,
neo4jExceptions.ClientError,
neo4jExceptions.SessionExpired,
ConnectionResetError,
OSError,
)
),
)
@ -846,6 +868,9 @@ class Neo4JStorage(BaseGraphStorage):
neo4jExceptions.TransientError,
neo4jExceptions.WriteServiceUnavailable,
neo4jExceptions.ClientError,
neo4jExceptions.SessionExpired,
ConnectionResetError,
OSError,
)
),
)
@ -1313,6 +1338,9 @@ class Neo4JStorage(BaseGraphStorage):
neo4jExceptions.TransientError,
neo4jExceptions.WriteServiceUnavailable,
neo4jExceptions.ClientError,
neo4jExceptions.SessionExpired,
ConnectionResetError,
OSError,
)
),
)
@ -1349,6 +1377,9 @@ class Neo4JStorage(BaseGraphStorage):
neo4jExceptions.TransientError,
neo4jExceptions.WriteServiceUnavailable,
neo4jExceptions.ClientError,
neo4jExceptions.SessionExpired,
ConnectionResetError,
OSError,
)
),
)
@ -1370,6 +1401,9 @@ class Neo4JStorage(BaseGraphStorage):
neo4jExceptions.TransientError,
neo4jExceptions.WriteServiceUnavailable,
neo4jExceptions.ClientError,
neo4jExceptions.SessionExpired,
ConnectionResetError,
OSError,
)
),
)