jeremyevans / sequel

Sequel: The Database Toolkit for Ruby
http://sequel.jeremyevans.net
Other
5k stars 1.07k forks source link

Connects to Snowflake but crashes when querying #2114

Closed ccoffey closed 11 months ago

ccoffey commented 11 months ago

Complete Description of Issue

I have added the following two gems (latest versions of each) to my Gemfile:

gem "sequel", "5.76.0"
gem "ruby-odbc", "0.999991" # Seems to be necessary to use Sequel.odbc

Then on a Rails console, it looks like I can connect (because it takes a second) but then it crashes when I try to query:

connection_str = [
  'DRIVER=/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib;',
  'SERVER=<account>.snowflakecomputing.com;',
  'UID=<uid>;',
  'PWD=<pwd>;',
].join('')

db = Sequel.odbc(drvconnect: connection_str)
=> #<Sequel::ODBC::Database: {:adapter=>:odbc, :drvconnect=>"...

db.fetch("select current_version();").all
[1]    14340 abort      rails c

Seems to crash if I execute any query, for example:

db["select 1;"].count
[1]    14798 abort      rails c

How do I debug this? Are there logs I can look at? I see nothing on the console before it crashes.

I've verified that I can connect using iodbctest and the same config:

Enter ODBC connect string (? shows list): dsn=testodbc1;pwd=<REDACTED>
Driver: 3.1.4 (Snowflake)

SQL>SELECT 1;

1
---
1

 result set 1 returned 1 rows.

Any help would be very much appreciated

Simplest Possible Self-Contained Example Showing the Bug

No response

Full Backtrace of Exception (if any)

No response

SQL Log (if any)

No response

Ruby Version

ruby 3.1.4p223

Sequel Version

5.76.0

jeremyevans commented 11 months ago

Sequel itself contains no native code. If you are getting a segfault/crash, it is a bug in the ruby-odbc native code or the underlying ODBC driver (or Ruby itself, but that seems unlikely in this case). You'll probably need to run the code under a C debugger such as gdb to track down the issue. Based on https://github.com/vendasta/sequel-snowflake/issues/16#issuecomment-1828471244, this appears to be a recently introduced bug in unixODBC, as downgrading unixODBC to 2.3.11 fixed the issue. Closing as this does not appear to be a bug in Sequel.

ccoffey commented 11 months ago

@jeremyevans you are likely correct, but I did tried the following:

gem uninstall ruby-odbc
gem install ruby-odbc -- --with-odbc-dir=/opt/homebrew/Cellar/unixodbc/2.3.11

However, I am still seeing the same crash 🤔 Any suggestions?

jeremyevans commented 11 months ago

Unfortunately, I don't have any other than my previous suggestion of running it under gdb (maybe lldb would work as well) and seeing where the crash occurs. I haven't actually tested Sequel's odbc adapter with unixodbc (I test the Sequel odbc adapter on Windows), though I have had reports that it works.

manishaca commented 7 months ago

@ccoffey were you able to get around this issue?