Package: ruby-mysql2 / 0.3.16-2

correct_mysql_init.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Description: Added call to mysql_library_init during initialization of the gem
      This call must be performed before trying to call mysql_init from
      multiple threads
      Reference: http://dev.mysql.com/doc/refman/5.1/en/mysql-init.html
      Minimal reproduction of the problem if mysql_library_init is not called
    
        require 'mysql2'
    
        def connect
          Mysql2::Client.new()
        end
    
        threads = [0,1].map {
          Thread.new { connect }
        }
        threads.map(&:join)
        puts "OK!"
Author: Michael Kruglos <michael@kruglos.com>
Reviewed-by: C├ędric Boutillier <boutil@debian.org>
Origin: upstream,https://github.com/brianmario/mysql2/commit/de48627ee89b9dfd7d966f3ea747e95a48085792.patch
Last-Update: 2014-07-30

--- a/ext/mysql2/client.c
+++ b/ext/mysql2/client.c
@@ -1237,6 +1237,13 @@
     }
   }
 
+  /* Initializing mysql library, so different threads could call Client.new */
+  /* without race condition in the library */
+  if (mysql_library_init(0, NULL, NULL) != 0) {
+    rb_raise(rb_eRuntimeError, "Could not initialize MySQL client library");
+    return;
+  }
+
 #if 0
   mMysql2      = rb_define_module("Mysql2"); Teach RDoc about Mysql2 constant.
 #endif