Skip to content

Fix race condition in bolt connection pool - #1346

Merged
robsdedude merged 2 commits into
neo4j:6.xfrom
robsdedude:fix/bolt-pool-race-condition
Sep 24, 2026
Merged

robsdedude merged 2 commits into
neo4j:6.xfrom
robsdedude:fix/bolt-pool-race-condition

Conversation

@robsdedude

Copy link
Copy Markdown
Member

The pool tries to acquire an idle connection first. If no idle connection is
available, it puts itself into a queue waiting for another thread/task to return
a connection before trying again.

However, there is no protection against a connection being returned between the
attempt to acquire an idle connection and the enqueuing. Therefore, it could
happen that a thread waits indefinitely like this:

Assume max pool size of 1

  • T1 creates & acquires con1
  • T2 checks for idle connections => None
  • T1 releases con1
  • T2 acquires lock to be able to wait for the release event
  • T1 terminates
  • T2 times out waiting for Godot

Closes: DRIVERS-578

The pool tries to acquire an idle connection first. If no idle connection is
available, it puts itself into a queue waiting for another thread/task to return
a connection before trying again.

However, there is no protection against a connection being returned between the
attempt to acquire an idle connection and the enqueuing. Therefore, it could
happen that a thread waits indefinitely like this:

Assume max pool size of 1

 * T1 creates & acquires con1
 * T2 checks for idle connections => None
 * T1 releases con1
 * T2 acquires lock to be able to wait for the release event
 * T1 terminates
 * T2 times out waiting for Godot
@robsdedude robsdedude changed the title Fix/bolt pool race condition Fix race condition in bolt connection pool Sep 23, 2026
@robsdedude
robsdedude marked this pull request as ready for review September 23, 2026 21:06

@StephenCathcart StephenCathcart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good

@robsdedude
robsdedude merged commit b625c52 into neo4j:6.x Sep 24, 2026
30 checks passed
@robsdedude
robsdedude deleted the fix/bolt-pool-race-condition branch September 24, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants