Failed to read from defunct connection (Jupyter notebook, python driver )

I try to import data into a Neo4j VM in Azure.

This code works:

def create_article(tx):
    tx.run("CREATE (a:ARTICLE)")

session.read_transaction(create_article)

But this code doesn't work:

def create_node_article(tx, id, title, label):
    tx.run("CREATE (a:ARTICLE {id:$id, title:$title, label:$label})", id=id, title=title, label=label)

for index, row in df_article_ids.iterrows():
    session.read_transaction(create_node_article, row['id'], row['cleaned_best_title'], row['label'])

I have the error:

Transaction failed and will be retried in 1.0608892687544587s (Failed to read from defunct connection Address(host='IP', port=7687) (Address(host='IP', port=7687)))

I don't know what I have to change or check. I also tried Neo4j Desktop and I have the same error.

Neo4j version: 4.1.3

Could you include the full code sample that you're trying to get working?

Hello,

I have the same problem with the official Python Driver and Neo4j. I've been receiving this error: "Failed to read from defunct connection IPv4Address(('HOST', 7687)) (IPv4Address(('IPADDRESS', 7687)))"

It seems like there are already open GitHub issues for this, but there are no updates yet as far as I can tell.

Has anyone on this forum managed to solve this issue?

For me, I tend to see this error message particularly often on those days when my python code updates the Neo4j graph database with csv files around 1G or more. Based on what I read on those GitHub threads, at some point the Python driver loses the connection to Neo4j if a considerable amount of times has passed. But I still find that a bit odd because on other days the updates finish in about 6 hours so clearly the connection remains even after a couple of hours.

I'm going to try to increase the

max_connection_lifetime=200

parameter so that the connection is maintained longer but people are saying that does not solve the problem.

Thanks

Did you find a resolution to this?

I moved from a server installation of Neo4j community to Aura and am starting to regret it because I'm finding Aura both a lot slower and has this error every couple of hours on our live system. It recovers after a few seconds and then works again, but I've had comments from clients.

I'm on:

  • Ubuntu Server 22.04.3 LTS
  • Python 3.10.12
  • Neo4j driver: neo4j==5.13.0

My connection string looks like this:

GraphDatabase.driver(DATABASE_URL, auth=(DATABASE_USERNAME, DATABASE_PASSWORD), max_connection_lifetime=max_connection_lifetime)

max_connection_lifetime is 50 minutes. 50*60 seconds. I read that this can solve the issue, but it doesn't.

I get this error each time it fails:

neo4j.exceptions.SessionExpired: Failed to read from defunct connection IPv4Address(('XXX', 7687)) (ResolvedIPv4Address(('xx.xx.xx.xx', 7687)))

Followed by this kind of error when I try the request again during the period it's re-establishing connection.

neo4j.exceptions.NotALeader: {code: Neo.ClientError.Cluster.NotALeader} {message: Unable to route to database 'neo4j'. Unable to get bolt address of leader.}