File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -378,6 +378,8 @@ class ConnectionPool(object):
378
378
""" A collection of connections to one or more server addresses.
379
379
"""
380
380
381
+ closed = False
382
+
381
383
def __init__ (self , connector ):
382
384
self .connector = connector
383
385
self .connections = {}
@@ -393,6 +395,9 @@ def acquire(self, address):
393
395
""" Acquire a connection to a given address from the pool.
394
396
This method is thread safe.
395
397
"""
398
+ if self .closed :
399
+ raise ServiceUnavailable ("This connection pool is closed so no new "
400
+ "connections may be acquired" )
396
401
with self .lock :
397
402
try :
398
403
connections = self .connections [address ]
@@ -433,6 +438,7 @@ def close(self):
433
438
This method is thread safe.
434
439
"""
435
440
with self .lock :
441
+ self .closed = True
436
442
for address in list (self .connections ):
437
443
self .remove (address )
438
444
Original file line number Diff line number Diff line change 20
20
21
21
from socket import create_connection
22
22
23
- from neo4j .v1 import ConnectionPool
23
+ from neo4j .v1 import ConnectionPool , ServiceUnavailable
24
24
25
25
from test .util import ServerTestCase
26
26
@@ -98,3 +98,9 @@ def test_releasing_twice(self):
98
98
self .assert_pool_size (address , 0 , 1 )
99
99
self .pool .release (connection )
100
100
self .assert_pool_size (address , 0 , 1 )
101
+
102
+ def test_cannot_acquire_after_close (self ):
103
+ with ConnectionPool (lambda a : QuickConnection (create_connection (a ))) as pool :
104
+ pool .close ()
105
+ with self .assertRaises (ServiceUnavailable ):
106
+ _ = pool .acquire ("X" )
You can’t perform that action at this time.
0 commit comments