Multi-threaded DBI causing segfault

X

Xavier Noëlle

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 :)

=================
#! /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 = 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
=================
 
R

Roger Pack

/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
 
X

Xavier Noëlle

2010/1/20 Roger Pack said:
/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
 
F

Florian Gilcher

=20 http://wiki.github.com/rdp/ruby_tutorials_core/building-mri#debug_build
=20
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:
=20
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b77517 in st_foreach () from /usr/lib/libruby1.8.so.1.8

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=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top