[DRE-maint] Bug#770896: ruby-mysql2: libmysql may not be called correctly during initialization of the gem

Cédric Boutillier boutil at debian.org
Mon Nov 24 23:32:10 UTC 2014


Package: ruby-mysql2
Severity: important



Hi,

Currently, the MySQL library is not properly initialized when the gem is
loaded, which can prevent connections from other threads, because of a
race condition.

This is fixed by an upstream commit which initialized correctly the
MySQL library:

de48627ee89b9dfd7d966f3ea747e95a48085792
 Added call to mysql_library_init during initialization of the gem

 Reproduced below:


-------------------------8<-----------------------
 Author:     Michael Kruglos <michael at kruglos.com>
AuthorDate: Wed Jul 30 22:52:50 2014 +0300
Commit:     Michael Kruglos <michael at kruglos.com>
CommitDate: Thu Jul 31 11:26:31 2014 +0300

    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!"
---
 ext/mysql2/client.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c
index c22b5b8..71a7a35 100644
--- a/ext/mysql2/client.c
+++ b/ext/mysql2/client.c
@@ -1235,6 +1235,13 @@ void init_mysql2_client() {
     }
   }

+  /* 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

 ----------8<------------------------------






-- System Information:
Debian Release: jessie/sid
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'testing'), (100, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-ruby-extras-maintainers/attachments/20141125/6c36f733/attachment.sig>


More information about the Pkg-ruby-extras-maintainers mailing list