File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def stat(self):
58
58
"""Returns (opened connections, free connections, waiters)"""
59
59
return (self ._opened_conns , len (self ._free_conn ), len (self ._waitings ))
60
60
61
- def _get_conn (self ):
61
+ def _get_conn (self ): # -> Future[connection]
62
62
now = self .io_loop .time ()
63
63
64
64
# Try to reuse in free pool
@@ -76,13 +76,19 @@ def _get_conn(self):
76
76
if self .max_open == 0 or self ._opened_conns < self .max_open :
77
77
self ._opened_conns += 1
78
78
_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
80
82
81
83
# Wait to other connection is released.
82
84
fut = Future ()
83
85
self ._waitings .append (fut )
84
86
return fut
85
87
88
+ def _on_connect (self , fut ):
89
+ if fut .exception ():
90
+ self ._opened_conns -= 1
91
+
86
92
def _put_conn (self , conn ):
87
93
if (len (self ._free_conn ) < self .max_idle and
88
94
self .io_loop .time () - conn .connected_time < self .max_recycle_sec ):
You can’t perform that action at this time.
0 commit comments