Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Stable/1.3.x - Backport for #18135 -- Sleeping Database Connections on Startup with MySQL #73

Closed
wants to merge 1 commit into from

2 participants

@newmaniese

This is a fix for #18135, which was closed before the patches were applied. I have tested and the DB connections are properly closed.

@newmaniese newmaniese [1.3.x] Fixed #18135 -- Sleeping Database Connections on Startup with…
… MySQL - Made sure server version checking does not leave open connection behind. - Backport of cfc2561
a0a751a
@akaariai
Collaborator

pulled in manually

@akaariai akaariai closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2012
  1. @newmaniese

    [1.3.x] Fixed #18135 -- Sleeping Database Connections on Startup with…

    newmaniese authored
    … MySQL - Made sure server version checking does not leave open connection behind. - Backport of cfc2561
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +12 −3 django/db/backends/mysql/base.py
View
15 django/db/backends/mysql/base.py
@@ -334,10 +334,19 @@ def _rollback(self):
def get_server_version(self):
if not self.server_version:
+ new_connection = False
if not self._valid_connection():
- self.cursor()
- m = server_version_re.match(self.connection.get_server_info())
+ # Ensure we have a connection with the DB by using a temporary
+ # cursor
+ new_connection = True
+ self.cursor().close()
+ 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
Something went wrong with that request. Please try again.