Skip to content

Missing resource closure warnings #949

@solter

Description

@solter

Bug Report

When the driver is used after it has been closed, it may open up new resources. But the _closed state is not reset, and so deleting a driver with open resources may leave abandoned, open resources.

Example code

Here is an example of how this might occur:

import neo4j

driver = neo4j.GraphDatabase.driver(uri, (username, password))

driver.verify_connectivity()
print(f"{driver._closed}, {len(driver._pool.connections}") # False, 1

driver.close()
print(f"{driver._closed}, {len(driver._pool.connections}") # True, 0

# del driver # this would be safe now

driver.verify_connectivity()
print(f"{driver._closed}, {len(driver._pool.connections}") # True, 1

# driver has unclosed resources
del driver # should generate an unclosed resource warning, but does not

My Environment

Python Version: 3.11
Driver Version: 5.10.0
Server Version and Edition: Neo4j Desktop, Neo4j DBMS 5.9.0
Operating System: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions