List:Commits« Previous MessageNext Message »
From:msvensson Date:February 16 2006 12:02pm
Subject:bk commit into 5.0 tree (msvensson:1.2045) BUG#2845
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2045 06/02/16 12:02:38 msvensson@neptunus.(none) +4 -0
  Bug#2845 client fails to reconnect if using TCP/IP
  - Detect that connection to server has been broken in "net_clear". Since 
    net_clear is always called before we send command to server, we can be sure
    that server has not received the command.

  sql/net_serv.cc
    1.85 06/02/16 12:02:34 msvensson@neptunus.(none) +74 -11
    Make "net_clear" detect if connection with server has been broken by 
    performing a select. If the select returns that there are data to read but
    no data can be read, that means the connection is broken. Signal disconnected
    to "write" functions by setting error to 2. 

  mysql-test/t/wait_timeout.test
    1.2 06/02/16 12:02:34 msvensson@neptunus.(none) +18 -2
    Test that same error message is returned when disconnected regardless of connection is
socket or TCP
    Decrease sleep times

  mysql-test/t/wait_timeout-master.opt
    1.2 06/02/16 12:02:34 msvensson@neptunus.(none) +1 -1
    Decrease wait_timeout value to avoid unneccessary sleeps 

  mysql-test/r/wait_timeout.result
    1.2 06/02/16 12:02:34 msvensson@neptunus.(none) +8 -0
    Update test result

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	msvensson
# Host:	neptunus.(none)
# Root:	/home/msvensson/mysql/bug2845/my50-bug2845

--- 1.84/sql/net_serv.cc	2005-09-13 01:55:43 +02:00
+++ 1.85/sql/net_serv.cc	2006-02-16 12:02:34 +01:00
@@ -194,29 +194,92 @@
   DBUG_RETURN(0);
 }
 
-	/* Remove unwanted characters from connection */
+
+/*
+  Check if there is any data to be read from the socket
+
+  SYNOPSIS
+    net_data_is_ready()
+    sd   socket descriptor
+
+  DESCRIPTION
+    Check if there is any data to be read from the socket.
+
+  RETURN VALUES
+    0	No data to read
+    1	Data or EOF to read
+*/
+
+static my_bool net_data_is_ready(my_socket sd)
+{
+  fd_set sfds;
+  struct timeval tv;
+  int res;
+
+  FD_ZERO(&sfds);
+  FD_SET(sd, &sfds);
+
+  tv.tv_sec= tv.tv_usec= 0;
+
+  if ((res= select(sd+1, &sfds, NULL, NULL, &tv)) < 0)
+    return FALSE;
+  else
+    return test(res ? FD_ISSET(sd, &sfds) : 0);
+}
+
+
+/*
+  Remove unwanted characters from connection
+  and check if disconnected
+
+  SYNOPSIS
+    net_clear()
+    net			NET handler
+
+  DESCRIPTION
+    Read from socket until there is nothing more to read. Discard
+    what is read.
+
+    If there is anything when to read 'net_clear' is called this
+    normally indicates an error in the protocol.
+
+    When connection is properly closed (for TCP it means with
+    a FIN packet), then select() considers a socket "ready to read",
+    in the sense that there's EOF to read, but read() returns 0.
+
+*/
 
 void net_clear(NET *net)
 {
+  int count;
   DBUG_ENTER("net_clear");
-#if !defined(EXTRA_DEBUG) && !defined(EMBEDDED_LIBRARY)
+#if !defined(EMBEDDED_LIBRARY)
+  while(net_data_is_ready(net->vio->sd))
   {
-    int count;					/* One may get 'unused' warn */
-    my_bool old_mode;
-    if (!vio_blocking(net->vio, FALSE, &old_mode))
+    /* The socket is ready */
+    if ((count= vio_read(net->vio, (char*) (net->buff),
+                         (uint32) net->max_packet)) > 0)
     {
-      while ((count = vio_read(net->vio, (char*) (net->buff),
-			       (uint32) net->max_packet)) > 0)
-	DBUG_PRINT("info",("skipped %d bytes from file: %s",
-			   count, vio_description(net->vio)));
-      vio_blocking(net->vio, TRUE, &old_mode);
+      DBUG_PRINT("info",("skipped %d bytes from file: %s",
+                         count, vio_description(net->vio)));
+#ifdef EXTRA_DEBUG
+      fprintf(stderr,"skipped %d bytes from file: %s\n",
+              count, vio_description(net->vio));
+#endif
+    }
+    else
+    {
+      DBUG_PRINT("info",("socket ready but only EOF to read - disconnected"));
+      net->error= 2;
+      break;
     }
   }
-#endif /* EXTRA_DEBUG */
+#endif
   net->pkt_nr=net->compress_pkt_nr=0;		/* Ready for new command */
   net->write_pos=net->buff;
   DBUG_VOID_RETURN;
 }
+
 
 	/* Flush write_buffer if not empty. */
 

--- 1.1/mysql-test/r/wait_timeout.result	2005-10-11 18:12:10 +02:00
+++ 1.2/mysql-test/r/wait_timeout.result	2006-02-16 12:02:34 +01:00
@@ -6,3 +6,11 @@
 select 3;
 3
 3
+select 1;
+1
+1
+select 2;
+ERROR HY000: MySQL server has gone away
+select 3;
+3
+3

--- 1.1/mysql-test/t/wait_timeout-master.opt	2005-10-11 18:12:10 +02:00
+++ 1.2/mysql-test/t/wait_timeout-master.opt	2006-02-16 12:02:34 +01:00
@@ -1 +1 @@
---wait-timeout=2
+--wait-timeout=1

--- 1.1/mysql-test/t/wait_timeout.test	2005-10-11 18:12:10 +02:00
+++ 1.2/mysql-test/t/wait_timeout.test	2006-02-16 12:02:34 +01:00
@@ -3,9 +3,25 @@
 #
 --disable_reconnect
 select 1;
-# wait_timeout is 2, so we should get disconnected now
---sleep 5
+# wait_timeout is 1, so we should get disconnected now
+--sleep 2
+# When the connection is closed in this way, the error code should
+# be consistent see bug#2845 for an explanation
 --error 2006
 select 2;
 --enable_reconnect
 select 3;
+
+# Do the same test as above on a TCP connection
+connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,);
+--disable_reconnect
+select 1;
+# wait_timeout is 1, so we should get disconnected now
+--sleep 2
+# When the connection is closed in this way, the error code should
+# be consistent see bug#2845 for an explanation
+--error 2006
+select 2;
+--enable_reconnect
+select 3;
+disconnect con1;
Thread
bk commit into 5.0 tree (msvensson:1.2045) BUG#2845msvensson16 Feb