Skip to content

Commit 00f4739

Browse files
authored
fix to decrement open connections count on connect exception (#1)
1 parent 4223e5d commit 00f4739

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="Tornado-MySQL",
6-
version="0.5.1",
6+
version="0.5.2",
77
url='https://github.com/PyMySQL/Tornado-MySQL',
88
author='INADA Naoki',
99
author_email='songofacandy@gmail.com',

tornado_mysql/pools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,19 @@ def _get_conn(self):
7272
if self.max_open == 0 or self._opened_conns < self.max_open:
7373
self._opened_conns += 1
7474
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
7678

7779
# Wait to other connection is released.
7880
fut = Future()
7981
self._waitings.append(fut)
8082
return fut
8183

84+
def _on_connect(self, fut):
85+
if fut.exception():
86+
self._opened_conns -= 1
87+
8288
def _put_conn(self, conn):
8389
if (len(self._free_conn) < self.max_idle and
8490
self.io_loop.time() - conn.connected_time < self.max_recycle_sec):

0 commit comments

Comments
 (0)