From 23558d6b92827ac7eb8a39c312d554fe2d2efda8 Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sat, 2 Feb 2019 17:23:16 -0800 Subject: [PATCH 1/2] Fixed load data infile file handle bug. -The file handle for that reads the local file for a load data local infile command is never closed. This can cause issues if you are running hundreds of load data commands as you run out of python IO handles. -Fixed the bug by adding a finally clause to always close the files. --- lib/mysql/connector/connection.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mysql/connector/connection.py b/lib/mysql/connector/connection.py index 2fb7240..b02be91 100644 --- a/lib/mysql/connector/connection.py +++ b/lib/mysql/connector/connection.py @@ -399,6 +399,8 @@ def _handle_load_data_infile(self, filename): """Handle a LOAD DATA INFILE LOCAL request""" try: data_file = open(filename, 'rb') + return self._handle_ok(self._send_data(data_file, + send_empty_packet=True)) except IOError: # Send a empty packet to cancel the operation try: @@ -408,9 +410,13 @@ def _handle_load_data_infile(self, filename): "MySQL Connection not available.") raise errors.InterfaceError( "File '{0}' could not be read".format(filename)) + finally: + try: + data_file.close() + except IOError, NameError: + # don't worry if the file was never opened + pass - return self._handle_ok(self._send_data(data_file, - send_empty_packet=True)) def _handle_result(self, packet): """Handle a MySQL Result From 96ffd1398806d703801cecd45beda8465a3818ad Mon Sep 17 00:00:00 2001 From: Micah Gale Date: Sun, 3 Feb 2019 09:52:19 -0800 Subject: [PATCH 2/2] Updated copyright statement to the new year. --- lib/mysql/connector/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mysql/connector/connection.py b/lib/mysql/connector/connection.py index b02be91..c40ff8e 100644 --- a/lib/mysql/connector/connection.py +++ b/lib/mysql/connector/connection.py @@ -1,4 +1,5 @@ -# Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2018, 2019 Oracle and/or its affiliates. +# All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2.0, as