views:

797

answers:

2

[Edited to use much simpler code which shows the problem]

The following code gives a segmentation fault on the last line

require 'rubygems'
gem 'mysql'
gem 'dbi'
require 'dbi'
require 'mysql'

dsn = "DBI:Mysql:DATABASE:www.HOST.net" # redacted
dbh = DBI.connect(dsn, "USERNAME", "PASSWORD") # redacted

sth = dbh.execute("select  * from TABLE where numeric_value is not null limit 10;") # redacted

It's definitely the last line that's causing the problem -- a print statement on the next line doesn't ever get executed.

Does anyone know why such a simple attempt would fail?

I'm running this on Windows, in case that makes a difference.

Thanks,

Ben

A: 

I don't know why you're getting a segfault in this code.

It is possible that, for instance, if you overrun the bounds of the array, you may not actually segfault until you try to run the code or access the memory that you overwrote. So you could have a system that runs for days before it segfaults if it only wrote in memory the process owns in an area it didnt' access often.

Sam Hoice
+1  A: 

This could be any number of things, from the version of DBI, Mysql gem, mysql version, and ruby version.

Unfortunately ruby isn't a first class citizen on windows, nor are all configurations tested extensively on it.

First enable debugging on your VM to reproduce this issue with more information about where and why the segfault is happening. Pass the -d option the VM. From there you will hopefully have more info to where to look for the solution.

I'd suggest, check your patch level of your VM

ruby --version

I'd also check the level of DBI, and Mysql

  # if you are using gems
  gem list --local

You could also switch how you are accessing Mysql, ActiveRecord uses it's own code to connect to mysql, which is more extensively tested. May not be the best solution but should not rule it out.

Scott Markwell
Thanks Scott, I'll check those things out.
Ben