Debugging neobolt.exceptions.ServiceUnavailable error

Hello, I seem to be running into the following error and can't pinpoint the cause:

neobolt.exceptions.ServiceUnavailable: Failed to read from defunct connection Address(host='localhost', port=7687) (Address(host='127.0.0.1', port=7687))

My general workflow is something like this:

uri = "bolt://localhost:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", mypass))
db = driver.session()
with db.begin_transaction() as tx:
    for d in my_data:
        q = get_query(d)
        tx.run(q)
        tx.success = True
driver.close()

The code runs fine for a while, and several nodes and relationships are successfully added to the graph. But then I will randomly get the error pasted above. Is there anything unusual in my code snippet? What might be the cause of the above error?