File tree 2 files changed +18
-5
lines changed 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -1250,13 +1250,23 @@ def release(self, connection):
1250
1250
def owns_connection (self , connection ):
1251
1251
return connection .pid == self .pid
1252
1252
1253
- def disconnect (self ):
1254
- "Disconnects all connections in the pool"
1253
+ def disconnect (self , inuse_connections = True ):
1254
+ """
1255
+ Disconnects connections in the pool
1256
+
1257
+ If ``inuse_connections`` is True, disconnect connections that are
1258
+ current in use, potentially by other threads. Otherwise only disconnect
1259
+ connections that are idle in the pool.
1260
+ """
1255
1261
self ._checkpid ()
1256
1262
with self ._lock :
1257
- all_conns = chain (self ._available_connections ,
1258
- self ._in_use_connections )
1259
- for connection in all_conns :
1263
+ if inuse_connections :
1264
+ connections = chain (self ._available_connections ,
1265
+ self ._in_use_connections )
1266
+ else :
1267
+ connections = self ._available_connections
1268
+
1269
+ for connection in connections :
1260
1270
connection .disconnect ()
1261
1271
1262
1272
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ def get_master_address(self):
108
108
if self .is_master :
109
109
if self .master_address != master_address :
110
110
self .master_address = master_address
111
+ # disconnect any idle connections so that they reconnect
112
+ # to the new master the next time that they are used.
113
+ self .disconnect (inuse_connections = False )
111
114
return master_address
112
115
113
116
def rotate_slaves (self ):
You can’t perform that action at this time.
0 commit comments