File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def stat(self):
5858 """Returns (opened connections, free connections, waiters)"""
5959 return (self ._opened_conns , len (self ._free_conn ), len (self ._waitings ))
6060
61- def _get_conn (self ):
61+ def _get_conn (self ): # -> Future[connection]
6262 now = self .io_loop .time ()
6363
6464 # Try to reuse in free pool
@@ -76,13 +76,19 @@ def _get_conn(self):
7676 if self .max_open == 0 or self ._opened_conns < self .max_open :
7777 self ._opened_conns += 1
7878 _debug ("Creating new connection:" , self .stat ())
79- return connect (** self .connect_kwargs )
79+ fut = connect (** self .connect_kwargs )
80+ fut .add_done_callback (self ._on_connect ) # self._opened_conns -=1 on exception
81+ return fut
8082
8183 # Wait to other connection is released.
8284 fut = Future ()
8385 self ._waitings .append (fut )
8486 return fut
8587
88+ def _on_connect (self , fut ):
89+ if fut .exception ():
90+ self ._opened_conns -= 1
91+
8692 def _put_conn (self , conn ):
8793 if (len (self ._free_conn ) < self .max_idle and
8894 self .io_loop .time () - conn .connected_time < self .max_recycle_sec ):
You can’t perform that action at this time.
0 commit comments