neo4j / neo4j-python-driver

Neo4j Bolt driver for Python
https://neo4j.com/docs/api/python-driver/current/
Other
893 stars 187 forks source link

ServiceUnavailable Failed to read from defunct connection with Flask uwsgi neo4j #974

Closed duclinhfetel closed 11 months ago

duclinhfetel commented 11 months ago

Issue

I use Flask + uwsgi + neo4j. With a large number of requests at the same time, uwsgi forks out many workers to handle the request, then I get the error below:

neo4j.exceptions.ServiceUnavailable: Failed to read from defunct connection IPv4Address(('neo4j', 7687)) (ResolvedIPv4Address(('172.23.0.5', 7687)))

Can anyone help me fix this issue? Thanks.

my neo4j driver config :

config = {
    "uri": "bolt://ip:7687", 
    "auth": ("neo4j", "password"),
    "encrypted": False,
    "max_connection_lifetime": 30 * 60,  
    "max_connection_pool_size": 50,
    "connection_acquisition_timeout": 2*60,  
    "connection_timeout":15
}
# init neo4j driver
driver = GraphDatabase.driver(**config)

# query with session
with driver.session() as session:
    results = session.run(query).to_eager_result()

uwsgi config

...
enable-threads = true
processes = 32                      ; Maximum number of workers allowed

My Environment