Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Michael Newman Anssi Kääriäinen
Michael Newman

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

Michael Newman [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
Anssi Kääriäinen
Owner

pulled in manually

Anssi Kääriäinen akaariai closed this May 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 18, 2012
Michael Newman [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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 12 additions and 3 deletions. Show diff stats Hide diff stats

  1. 15  django/db/backends/mysql/base.py
15  django/db/backends/mysql/base.py
@@ -334,10 +334,19 @@ def _rollback(self):
334 334
 
335 335
     def get_server_version(self):
336 336
         if not self.server_version:
  337
+            new_connection = False
337 338
             if not self._valid_connection():
338  
-                self.cursor()
339  
-            m = server_version_re.match(self.connection.get_server_info())
  339
+                # Ensure we have a connection with the DB by using a temporary
  340
+                # cursor
  341
+                new_connection = True
  342
+                self.cursor().close()
  343
+            server_info = self.connection.get_server_info()
  344
+            if new_connection:
  345
+                # Make sure we close the connection
  346
+                self.connection.close()
  347
+                self.connection = None
  348
+            m = server_version_re.match(server_info)
340 349
             if not m:
341  
-                raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
  350
+                raise Exception('Unable to determine MySQL version from version string %r' % server_info)
342 351
             self.server_version = tuple([int(x) for x in m.groups()])
343 352
         return self.server_version
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.