diff options
| author | Michael Newman <newmaniese@gmail.com> | 2012-05-27 18:24:35 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-05-27 18:45:08 +0300 |
| commit | 4423757c0c50afbe2470434778c8d5e5b4a70925 (patch) | |
| tree | e9a2f7c83f659656141b6d04f25ee69717f24e41 /django | |
| parent | a8a81aae20a81e012fddc24f3ede556501af64a2 (diff) | |
Fixed #18135 -- Close connection used for db version checking
On MySQL when checking the server version, a new connection could be
created but never closed. This could result in open connections on
server startup.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index ecbb02f31d..1df487bd92 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -418,11 +418,20 @@ class DatabaseWrapper(BaseDatabaseWrapper): @cached_property def mysql_version(self): if not self.server_version: + new_connection = False if not self._valid_connection(): + # Ensure we have a connection with the DB by using a temporary + # cursor + new_connection = True self.cursor().close() - m = server_version_re.match(self.connection.get_server_info()) + server_info = self.connection.get_server_info() + if new_connection: + # Make sure we close the connection + self.connection.close() + self.connection = None + m = server_version_re.match(server_info) if not m: - raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info()) + raise Exception('Unable to determine MySQL version from version string %r' % server_info) self.server_version = tuple([int(x) for x in m.groups()]) return self.server_version |
