Skip to content

Commit

Permalink
fix to decrement open connections count on connect exception (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
V0idmain authored Apr 7, 2017
1 parent 4223e5d commit 00f4739
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="Tornado-MySQL",
version="0.5.1",
version="0.5.2",
url='https://github.com/PyMySQL/Tornado-MySQL',
author='INADA Naoki',
author_email='[email protected]',
Expand Down
8 changes: 7 additions & 1 deletion tornado_mysql/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ def _get_conn(self):
if self.max_open == 0 or self._opened_conns < self.max_open:
self._opened_conns += 1
log.debug("Creating new connection: %s", self.stat())
return connect(**self.connect_kwargs)
fut = connect(**self.connect_kwargs)
fut.add_done_callback(self._on_connect) # self._opened_conns -=1 on exception
return fut

# Wait to other connection is released.
fut = Future()
self._waitings.append(fut)
return fut

def _on_connect(self, fut):
if fut.exception():
self._opened_conns -= 1

def _put_conn(self, conn):
if (len(self._free_conn) < self.max_idle and
self.io_loop.time() - conn.connected_time < self.max_recycle_sec):
Expand Down

0 comments on commit 00f4739

Please sign in to comment.