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 @@ -54,7 +54,7 @@ def stat(self):
54
54
"""Returns (opened connections, free connections, waiters)"""
55
55
return (self ._opened_conns , len (self ._free_conn ), len (self ._waitings ))
56
56
57
- def _get_conn (self ):
57
+ def _get_conn (self ): # -> Future[connection]
58
58
now = self .io_loop .time ()
59
59
60
60
# Try to reuse in free pool
@@ -72,13 +72,19 @@ def _get_conn(self):
72
72
if self .max_open == 0 or self ._opened_conns < self .max_open :
73
73
self ._opened_conns += 1
74
74
log .debug ("Creating new connection: %s" , self .stat ())
75
- return connect (** self .connect_kwargs )
75
+ fut = connect (** self .connect_kwargs )
76
+ fut .add_done_callback (self ._on_connect ) # self._opened_conns -=1 on exception
77
+ return fut
76
78
77
79
# Wait to other connection is released.
78
80
fut = Future ()
79
81
self ._waitings .append (fut )
80
82
return fut
81
83
84
+ def _on_connect (self , fut ):
85
+ if fut .exception ():
86
+ self ._opened_conns -= 1
87
+
82
88
def _put_conn (self , conn ):
83
89
if (len (self ._free_conn ) < self .max_idle and
84
90
self .io_loop .time () - conn .connected_time < self .max_recycle_sec ):
You can’t perform that action at this time.
0 commit comments