From 2fce53443f52c785bf657c9468edb5695a7c4f17 Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Tue, 1 Aug 2023 10:42:33 +0200 Subject: [PATCH] Fix missing lock acquisition in pool Fix some functions in the pool manipulating the routing information without holding the right lock. --- neo4j/io/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/neo4j/io/__init__.py b/neo4j/io/__init__.py index 7e0c0c009..7b8c63ee1 100644 --- a/neo4j/io/__init__.py +++ b/neo4j/io/__init__.py @@ -1334,10 +1334,11 @@ def deactivate(self, address): log.debug("[#0000] C: Deactivating address %r", address) # We use `discard` instead of `remove` here since the former # will not fail if the address has already been removed. - for database in self.routing_tables.keys(): - self.routing_tables[database].routers.discard(address) - self.routing_tables[database].readers.discard(address) - self.routing_tables[database].writers.discard(address) + with self.refresh_lock: + for database in self.routing_tables.keys(): + self.routing_tables[database].routers.discard(address) + self.routing_tables[database].readers.discard(address) + self.routing_tables[database].writers.discard(address) log.debug("[#0000] C: table=%r", self.routing_tables) super(Neo4jPool, self).deactivate(address) @@ -1345,8 +1346,9 @@ def on_write_failure(self, address): """ Remove a writer address from the routing table, if present. """ log.debug("[#0000] C: Removing writer %r", address) - for database in self.routing_tables.keys(): - self.routing_tables[database].writers.discard(address) + with self.refresh_lock: + for database in self.routing_tables.keys(): + self.routing_tables[database].writers.discard(address) log.debug("[#0000] C: table=%r", self.routing_tables)