List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:July 28 2010 8:11am
Subject:bzr commit into connector-net-6.2 branch (vvaintroub:880) Bug#55558
View as plain text  
#At file:///H:/connector_net/6.2/ based on revid:vvaintroub@stripped

  880 Vladislav Vaintroub	2010-07-28
      Bug#55558: 
      
      Always set internal datareader to null  if ExecuteReader fails
      to prevent subsequent "data reader is already open exception".
      
      Also, improve exception handling if network writes fail
      (can be reproduced when the database goes down
      just before ExecuteReader):
      
      * catch IOException in ExecuteReader
       in the catch block: 
      * abort  connection (close, without returning to pool)
      * wrap IOException into MySqlException 
      * rethrow

    modified:
      MySql.Data/Provider/Source/command.cs
=== modified file 'MySql.Data/Provider/Source/command.cs'
--- a/MySql.Data/Provider/Source/command.cs	2010-07-27 22:06:54 +0000
+++ b/MySql.Data/Provider/Source/command.cs	2010-07-28 08:11:56 +0000
@@ -350,7 +350,7 @@ namespace MySql.Data.MySqlClient
         /// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader1/*'/>
         public new MySqlDataReader ExecuteReader (CommandBehavior behavior)
         {
-
+            bool success = false;
             CheckState();
             Driver driver = connection.driver;
             lock (driver)
@@ -432,6 +432,7 @@ namespace MySql.Data.MySqlClient
                 statement.Execute();
                 // wait for data to return
                 reader.NextResult();
+                success = true;
                 return reader;
             }
             catch (TimeoutException tex)
@@ -444,6 +445,11 @@ namespace MySql.Data.MySqlClient
                 connection.HandleTimeoutOrThreadAbort(taex);
                 throw;
             }
+            catch (IOException ioex)
+            {
+                connection.Abort(); // Closes connection without returning it to the pool
+                throw new MySqlException(Resources.FatalErrorDuringExecute, ioex);
+            }
             catch (MySqlException ex)
             {
                 connection.Reader = null;
@@ -473,12 +479,22 @@ namespace MySql.Data.MySqlClient
             }
             finally
             {
-                if (connection != null && connection.Reader == null)
+                if (connection != null)
                 {
-                    // Comething want seriously wrong,  and reader would not be 
-                    // able to clear timeout on closing.
-                    // So we clear timeout here.
-                    ClearCommandTimer();
+                    if (connection.Reader == null)
+                    {
+                        // Something went seriously wrong,  and reader would not
+                        // be able to clear timeout on closing.
+                        // So we clear timeout here.
+                        ClearCommandTimer();
+                    }
+                    else if (!success)
+                    {
+                        // ExecuteReader failed. Reset Reader to null to 
+                        // prevent subsequent errors with DataReaderOpen
+                        connection.Reader.Close();
+                        connection.Reader = null;
+                    }
                 }
             }
         }


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20100728081156-nskknzn00zen6zr0.bundle
Thread
bzr commit into connector-net-6.2 branch (vvaintroub:880) Bug#55558Vladislav Vaintroub28 Jul