Multi-threaded DBI causing segfault

Hello,
I'm new to this mailing list, so do not hesitate to tell me if
everything's ok with my post.

I'm using DBI to connect to a MySQL database. I tried to reduce my
code as much as possible, knowing that:
- constants are valid (not '****') and lead to valid databases, valid
tables and the select returns a valid result
- removing the finish() does not solve the problem
- limiting the result size (eg: 'LIMIT 0, 30') does not solve the problem
- NB_THREADS is set to 50 to make it crash quickly (but, starting
from 2, any value makes it crash)
- as you can see below, I'm using Ruby 1.8.7 on Ubuntu 9.10 64 bits
- the file and line number in which the segmentation fault is
reported is variable (sometimes, it happens my own files)

The error output is as follow:
/usr/lib/ruby/1.8/dbd/mysql/statement.rb:36: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]

Question: is it a real bug or am I doing something wrong ?
If I'm wrong, where ?
If I'm not, is there a workaround to thread the execution of code
using DBI without a segfault ?

Thanks for any hint about my problem :slight_smile:

···

=================
#! /usr/bin/env ruby

require 'rubygems'
require 'dbi'

PRODUCTS_DB = '*****'

PRODUCTS_DB_HOST = '*****'
PRODUCTS_DB_USER = '*****'
PRODUCTS_DB_PASS = '****'

def getDbh()
  return DBI.connect("DBI:Mysql:#{PRODUCTS_DB}:"+
                     "#{PRODUCTS_DB_HOST}", PRODUCTS_DB_USER,
                     PRODUCTS_DB_PASS)
end

NB_THREADS = 50
threads = Array.new(NB_THREADS)

NB_THREADS.times() do |i|
  puts i
  threads[i] = Thread.new() do
    dbh = getDbh()

    while true
      hdl = dbh.execute('SELECT * FROM ****** LIMIT 0, 30') do |dummy|
        dummy[0]
      end
      hdl.finish()
      puts 'There'
    end
  end
end

threads.each() do |t|
  t.join()
end

--
Xavier NOELLE

/usr/lib/ruby/1.8/dbd/mysql/statement.rb:36: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]

Question: is it a real bug or am I doing something wrong ?
If I'm wrong, where ?
If I'm not, is there a workaround to thread the execution of code
using DBI without a segfault ?

Maybe use the mysql gem?

Also, you could run it in gdb to try to debug the cause.

http://wiki.github.com/rdp/ruby_tutorials_core/building-mri#debug_build

···

--
Posted via http://www.ruby-forum.com/\.

/usr/lib/ruby/1.8/dbd/mysql/statement.rb:36: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]

Question: is it a real bug or am I doing something wrong ?
If I'm wrong, where ?
If I'm not, is there a workaround to thread the execution of code
using DBI without a segfault ?

Maybe use the mysql gem?

I think that's the underlying gem used by DBI for dealing with MySQL,
would it really help ?

Also, you could run it in gdb to try to debug the cause.

http://wiki.github.com/rdp/ruby_tutorials_core/building-mri#debug_build

That was a good idea...in theory ! Because when I compile sources for
the exact same version (and patchlevel) of Ruby, I don't get the same
error...then I tried to run gdb directly on the standard Ubuntu 9.10
binary, but I think the error is not really helpful:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b77517 in st_foreach () from /usr/lib/libruby1.8.so.1.8

···

2010/1/20 Roger Pack <rogerpack2005@gmail.com>:

--
Xavier NOELLE

Be aware that the Debian (and thus Ubuntu) maintainers do mangle with the
standard Ruby distribution in non-trivial ways, so you might be their fault.

Although I cannot imagine why such a thing would happen, because their patches
usually concern packaging issues.

But it shouldn't hurt to file that as a bug report to them.

Regards,
Florian

···

On Jan 21, 2010, at 11:00 AM, Xavier Noëlle wrote:

Also, you could run it in gdb to try to debug the cause.

http://wiki.github.com/rdp/ruby_tutorials_core/building-mri#debug_build

That was a good idea...in theory ! Because when I compile sources for
the exact same version (and patchlevel) of Ruby, I don't get the same
error...then I tried to run gdb directly on the standard Ubuntu 9.10
binary, but I think the error is not really helpful:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b77517 in st_foreach () from /usr/lib/libruby1.8.so.1.8