Skip to content

Commit 9346ce8

Browse files
authored
Fix missing lock acquisition in pool (#953)
Fix some functions in the pool manipulating the routing information without holding the right lock.
1 parent 307349e commit 9346ce8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

neo4j/io/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,19 +1334,21 @@ def deactivate(self, address):
13341334
log.debug("[#0000] C: <ROUTING> Deactivating address %r", address)
13351335
# We use `discard` instead of `remove` here since the former
13361336
# will not fail if the address has already been removed.
1337-
for database in self.routing_tables.keys():
1338-
self.routing_tables[database].routers.discard(address)
1339-
self.routing_tables[database].readers.discard(address)
1340-
self.routing_tables[database].writers.discard(address)
1337+
with self.refresh_lock:
1338+
for database in self.routing_tables.keys():
1339+
self.routing_tables[database].routers.discard(address)
1340+
self.routing_tables[database].readers.discard(address)
1341+
self.routing_tables[database].writers.discard(address)
13411342
log.debug("[#0000] C: <ROUTING> table=%r", self.routing_tables)
13421343
super(Neo4jPool, self).deactivate(address)
13431344

13441345
def on_write_failure(self, address):
13451346
""" Remove a writer address from the routing table, if present.
13461347
"""
13471348
log.debug("[#0000] C: <ROUTING> Removing writer %r", address)
1348-
for database in self.routing_tables.keys():
1349-
self.routing_tables[database].writers.discard(address)
1349+
with self.refresh_lock:
1350+
for database in self.routing_tables.keys():
1351+
self.routing_tables[database].writers.discard(address)
13501352
log.debug("[#0000] C: <ROUTING> table=%r", self.routing_tables)
13511353

13521354

0 commit comments

Comments
 (0)