Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to decrement open connections count on connect exception #1

Merged
merged 3 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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