@@ -1596,8 +1596,14 @@ def _process_kill_cursors(self):
1596
1596
try :
1597
1597
self ._cleanup_cursor (True , cursor_id , address , sock_mgr ,
1598
1598
None , False )
1599
- except Exception :
1600
- helpers ._handle_exception ()
1599
+ except Exception as exc :
1600
+ if (isinstance (exc , InvalidOperation )
1601
+ and self ._topology ._closed ):
1602
+ # Raise the exception when client is closed so that it
1603
+ # can be caught in _process_periodic_tasks
1604
+ raise
1605
+ else :
1606
+ helpers ._handle_exception ()
1601
1607
1602
1608
# Don't re-open topology if it's closed and there's no pending cursors.
1603
1609
if address_to_cursor_ids :
@@ -1606,18 +1612,25 @@ def _process_kill_cursors(self):
1606
1612
try :
1607
1613
self ._kill_cursors (
1608
1614
cursor_ids , address , topology , session = None )
1609
- except Exception :
1610
- helpers ._handle_exception ()
1615
+ except Exception as exc :
1616
+ if (isinstance (exc , InvalidOperation ) and
1617
+ self ._topology ._closed ):
1618
+ raise
1619
+ else :
1620
+ helpers ._handle_exception ()
1611
1621
1612
1622
# This method is run periodically by a background thread.
1613
1623
def _process_periodic_tasks (self ):
1614
1624
"""Process any pending kill cursors requests and
1615
1625
maintain connection pool parameters."""
1616
- self ._process_kill_cursors ()
1617
1626
try :
1627
+ self ._process_kill_cursors ()
1618
1628
self ._topology .update_pool (self .__all_credentials )
1619
- except Exception :
1620
- helpers ._handle_exception ()
1629
+ except Exception as exc :
1630
+ if isinstance (exc , InvalidOperation ) and self ._topology ._closed :
1631
+ return
1632
+ else :
1633
+ helpers ._handle_exception ()
1621
1634
1622
1635
def __start_session (self , implicit , ** kwargs ):
1623
1636
# Raises ConfigurationError if sessions are not supported.
0 commit comments