Skip to content

Support configuring max_connection_idle_time in Neo4j driver #1978

@achantavy

Description

@achantavy

Support configuring max_connection_idle_time in Neo4j driver

Description

Currently, Cartography allows configuration of the Neo4j driver via parameters such as max_connection_lifetime and connection_timeout, but does not expose max_connection_idle_time. This setting was introduced in newer versions of the Neo4j Python driver to proactively close idle Bolt connections before the server does.

Supporting max_connection_idle_time in Cartography’s Neo4j driver initialization would let deployments avoid frequent SessionExpired or ConnectionResetError issues that occur when Aura or clustered Neo4j instances close idle connections.

The desired behavior is to allow users to configure this via the standard --neo4j-max-connection-idle-time CLI argument or environment variable, which then gets passed through to the GraphDatabase.driver() call.

Example:

driver = GraphDatabase.driver(
    uri,
    auth=auth,
    max_connection_lifetime=config.neo4j_max_connection_lifetime,
    max_connection_idle_time=config.neo4j_max_connection_idle_time,
)

Motivation

This feature helps prevent connection resets and SessionExpired errors that occur after several minutes of inactivity between stages in long-running sync jobs (e.g. during large GitHub ingestions).
Neo4j Aura and other managed clusters frequently close idle connections after ~3–5 minutes. Without this setting, the driver keeps stale sockets in its pool, which only fail on the next use, causing sync interruptions.

Allowing max_connection_idle_time aligns with Neo4j best practices and improves stability for large or multi-tenant syncs that may have uneven workloads across stages.

Alternatives Considered

  • Manual retry logic: Works but only recovers after failure
  • Refactoring to allow the Driver to be accessed throughout syncs instead of Session: very big and invasive refactor
  • Reducing max_connection_lifetime: Helps somewhat but does not address idle sockets specifically.

Adding max_connection_idle_time is the cleanest, officially supported solution.

Relevant Links

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions