MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:March 26 2009 11:17pm
Subject:bzr commit into mysql-5.0-bugteam branch (davi:2778) Bug#33899
View as plain text  
# At a local mysql-5.0-bugteam repository of davi

 2778 Davi Arnaut	2009-03-26
      Bug#33899: Deadlock in mysql_real_query with shared memory connections
      
      The problem is that the read and write methods of the shared
      memory transport (protocol) didn't react to asynchronous close
      events, which could lead to a lock up as the client would wait
      (until time out) for a server response that will never come.
      
      The solution is to also wait for close events while waiting
      for I/O from or to the server.
     @ mysql-test/r/shm.result
        Add test case result for Bug#33899
     @ mysql-test/t/shm.test
        Add test case for Bug#33899
     @ vio/viosocket.c
        Also wait for close events.

    modified:
      mysql-test/r/shm.result
      mysql-test/t/shm.test
      vio/viosocket.c
=== modified file 'mysql-test/r/shm.result'
--- a/mysql-test/r/shm.result	2007-09-24 10:42:44 +0000
+++ b/mysql-test/r/shm.result	2009-03-26 23:17:27 +0000
@@ -2152,4 +2152,11 @@ Warnings:
 Warning	1052	Column 'kundentyp' in group statement is ambiguous
 drop table t1;
 mysqld is alive
+SET @max_allowed_packet= @@global.max_allowed_packet;
+SET @net_buffer_length= @@global.net_buffer_length;
+SET GLOBAL max_allowed_packet= 1024;
+SET GLOBAL net_buffer_length= 1024;
+ERROR 1153 (08S01) at line 1: Got a packet bigger than 'max_allowed_packet' bytes
+SET GLOBAL max_allowed_packet= @max_allowed_packet;
+SET GLOBAL net_buffer_length= @net_buffer_length;
 End of 5.0 tests.

=== modified file 'mysql-test/t/shm.test'
--- a/mysql-test/t/shm.test	2007-09-24 10:42:44 +0000
+++ b/mysql-test/t/shm.test	2009-03-26 23:17:27 +0000
@@ -16,4 +16,23 @@ if (`SELECT '$shm' != 'ON'`){
 #
 --exec $MYSQLADMIN --no-defaults --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --shared-memory-base-name=HeyMrBaseNameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ping
 
+#
+# Bug #33899: Deadlock in mysql_real_query with shared memory connections
+#
+
+let $name= query_get_value("SHOW GLOBAL VARIABLES LIKE 'shared_memory_base_name'", Value, 1);
+let $stmt= `SELECT REPEAT('a', 2048)`;
+
+SET @max_allowed_packet= @@global.max_allowed_packet;
+SET @net_buffer_length= @@global.net_buffer_length;
+
+SET GLOBAL max_allowed_packet= 1024;
+SET GLOBAL net_buffer_length= 1024;
+
+--error 1
+--exec echo SELECT '$stmt'| $MYSQL --protocol=memory --shared-memory-base-name=$name 2>&1
+
+SET GLOBAL max_allowed_packet= @max_allowed_packet;
+SET GLOBAL net_buffer_length= @net_buffer_length;
+
 --echo End of 5.0 tests.

=== modified file 'vio/viosocket.c'
--- a/vio/viosocket.c	2009-02-10 22:47:54 +0000
+++ b/vio/viosocket.c	2009-03-26 23:17:27 +0000
@@ -479,26 +479,28 @@ int vio_read_shared_memory(Vio * vio, gp
   int length;
   int remain_local;
   char *current_postion;
+  HANDLE events[2];
 
   DBUG_ENTER("vio_read_shared_memory");
   DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %d", vio->sd, buf, size));
 
   remain_local = size;
   current_postion=buf;
+
+  events[0]= vio->event_server_wrote;
+  events[1]= vio->event_conn_closed;
+
   do
   {
     if (vio->shared_memory_remain == 0)
     {
-      HANDLE events[2];
-      events[0]= vio->event_server_wrote;
-      events[1]= vio->event_conn_closed;
       /*
         WaitForMultipleObjects can return next values:
          WAIT_OBJECT_0+0 - event from vio->event_server_wrote
          WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read anything
          WAIT_ABANDONED_0 and WAIT_TIMEOUT - fail.  We can't read anything
       */
-      if (WaitForMultipleObjects(2, (HANDLE*)&events,FALSE,
+      if (WaitForMultipleObjects(array_elements(events), events, FALSE,
                                  vio->net->read_timeout*1000) != WAIT_OBJECT_0)
       {
         DBUG_RETURN(-1);
@@ -537,19 +539,23 @@ int vio_write_shared_memory(Vio * vio, c
 {
   int length;
   uint remain;
-  HANDLE pos;
   int sz;
   char *current_postion;
+  HANDLE pos, events[2];
 
   DBUG_ENTER("vio_write_shared_memory");
   DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %d", vio->sd, buf, size));
 
   remain = size;
   current_postion = buf;
+
+  events[0]= vio->event_server_read;
+  events[1]= vio->event_conn_closed;
+
   while (remain != 0)
   {
-    if (WaitForSingleObject(vio->event_server_read, vio->net->write_timeout*1000) 
-                            != WAIT_OBJECT_0)
+    if (WaitForMultipleObjects(array_elements(events), events, FALSE,
+                               vio->net->write_timeout*1000) != WAIT_OBJECT_0)
     {
       DBUG_RETURN(-1);
     };


Attachment: [text/bzr-bundle] bzr/davi.arnaut@sun.com-20090326231727-r0jeim8zeuocxtgc.bundle
Thread
bzr commit into mysql-5.0-bugteam branch (davi:2778) Bug#33899Davi Arnaut27 Mar