@@ -1694,7 +1694,9 @@ def add_execution_profile(self, name, profile, pool_wait_timeout=5):
16941694 futures .update (session .update_created_pools ())
16951695 _ , not_done = wait_futures (futures , pool_wait_timeout )
16961696 if not_done :
1697- raise OperationTimedOut ("Failed to create all new connection pools in the %ss timeout." )
1697+ raise OperationTimedOut (
1698+ "Failed to create all new connection pools in the %ss timeout." % pool_wait_timeout ,
1699+ timeout = pool_wait_timeout )
16981700
16991701 def connection_factory (self , endpoint , host_conn = None , * args , ** kwargs ):
17001702 """
@@ -4794,6 +4796,7 @@ def _on_timeout(self, _attempts=0):
47944796 )
47954797 return
47964798
4799+ conn_in_flight = None
47974800 if self ._connection is not None :
47984801 try :
47994802 self ._connection ._requests .pop (self ._req_id )
@@ -4804,9 +4807,13 @@ def _on_timeout(self, _attempts=0):
48044807 except KeyError :
48054808 key = "Connection defunct by heartbeat"
48064809 errors = {key : "Client request timeout. See Session.execute[_async](timeout)" }
4807- self ._set_final_exception (OperationTimedOut (errors , self ._current_host ))
4810+ self ._set_final_exception (OperationTimedOut (errors , self ._current_host ,
4811+ timeout = self .timeout ,
4812+ in_flight = self ._connection .in_flight ))
48084813 return
48094814
4815+ # Capture connection stats before pool.return_connection() can alter state.
4816+ conn_in_flight = self ._connection .in_flight
48104817 pool = self .session ._pools .get (self ._current_host )
48114818 if pool and not pool .is_shutdown :
48124819 # Do not return the stream ID to the pool yet. We cannot reuse it
@@ -4831,7 +4838,9 @@ def _on_timeout(self, _attempts=0):
48314838 host = str (connection .endpoint ) if connection else 'unknown'
48324839 errors = {host : "Request timed out while waiting for schema agreement. See Session.execute[_async](timeout) and Cluster.max_schema_agreement_wait." }
48334840
4834- self ._set_final_exception (OperationTimedOut (errors , self ._current_host ))
4841+ self ._set_final_exception (OperationTimedOut (errors , self ._current_host ,
4842+ timeout = self .timeout ,
4843+ in_flight = conn_in_flight ))
48354844
48364845 def _on_speculative_execute (self ):
48374846 self ._timer = None
0 commit comments