Unable to use Ruby SDK 3.1.1 with Rails 6.1.3

Hello!

I’m trying to integrate yours brand new Ruby SDK 3 with our Rails 6 application. And unfortunatly stucked at connecting to cluster from dev environment with Segmentation fault error. Could you please guide me where I’m wrong? I’ll start from the beginning of my struggle.

My setup is: Ubuntu 16.04.7 LTS, rvm 1.29.12 (latest), Rails 6.1.3, Ruby 2.7.2p137, gem couchbase ‘3.1.1’ from yours sources, cmake version 3.20.2. Also I have installed libcouchbase-dev, libcouchbase2-bin, libssl-dev, build-essential.

I run Couchbase Server inside Docker container with docker-compose in such a way:
couchbase_server:
image: couchbase:community-6.6.0
restart: always
volumes:
- ./couchbase:/opt/couchbase/var
ports:
- “8091-8094:8091-8094”
- “11210:11210”

And through web panel it works great, everything works fine. I added travel-sample bucket and executed several N1QL queries, all good.

First I attempted to install couchbase gem from rubygems sources. I guess I tried everything that was generally available in the public docs, forums, etc. Building everytime fails at ~31%. I don’t know does it matter to install gem from rubygems?

And finally I installed it from yours sources with Bundler and Gemfile like this:
gem ‘couchbase’, ‘3.1.1’, platforms: %i[ruby], source: ‘https://packages.couchbase.com/clients/ruby/2.7.0/

With Irb it works fine! But when I try it in Rails console or from Controller actions all my dev environment fails. Here is log:

$ rails c
[2021-05-26 20:25:38.507] [18548,18548] [info] 2ms, couchbase backend has been initialized: {:sdk=>“3.1.1”, :backend=>“1.5.0”, :build_timestamp=>“2021-04-08 16:29:43”, :revision=>“a79d098eb238b3883e49e1738c35167642e8834f”, :platform=>“Linux-4.15.0-66-generic”, :cpu=>“x86_64”, :cc=>“GNU 9.3.1”, :cxx=>“GNU 9.3.1”, :ruby=>“2.7.0”, :spdlog=>“1.8.1”, :asio=>“1.18.0”, :snappy=>“1.1.8”, :http_parser=>“2.9.4”, :openssl_headers=>“OpenSSL 1.1.1g FIPS 21 Apr 2020”, :openssl_runtime=>“OpenSSL 1.1.1g FIPS 21 Apr 2020”}
Running via Spring preloader in process 18575
Loading development environment (Rails 6.1.3)
irb: warn: can’t alias context from irb_context.

2.7.2 :001 > options = Couchbase::Cluster::ClusterOptions.new
=> #<Couchbase::Options::Cluster:0x0000000006e8b1a0 @authenticator=nil>

2.7.2 :002 > options.authenticate(“ADMIN”, “PASSWORD”)
=> #<Couchbase::PasswordAuthenticator:0x0000000003956e30 @username=“ADMIN”, @password=“PASSWORD”, @allowed_sasl_mechanisms=[:scram_sha512, :scram_sha256, :scram_sha1]>

2.7.2 :003 > cluster = Couchbase::Cluster.connect(“couchbase://127.0.0.1”, options)
/home/user/.rvm/gems/ruby-2.7.2@brands_api/gems/couchbase-3.1.1-x86_64-linux/lib/couchbase/cluster.rb:415: [BUG] Segmentation fault at 0x00007f5b2de7a780
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

– Control frame information -----------------------------------------------
c:0055 p:---- s:0321 e:000320 CFUNC :new
c:0054 p:0524 s:0317 e:000316 METHOD /home/user/.rvm/gems/ruby-2.7.2@brands_api/gems/couchbase-3.1.1-x86_64-linux/lib/couchbase/cluster.rb:415 [FINISH]
c:0053 p:---- s:0307 e:000306 CFUNC :new
c:0052 p:0017 s:0301 e:000300 METHOD /home/user/.rvm/gems/ruby-2.7.2@brands_api/gems/couchbase-3.1.1-x86_64-linux/lib/couchbase/cluster.rb:65
c:0051 p:0019 s:0295 E:000d18 EVAL (irb):3 [FINISH]
c:0050 p:---- s:0291 e:000290 CFUNC :eval
c:0049 p:0020 s:0283 e:000282 METHOD /home/user/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/irb/workspace.rb:114
c:0048 p:0059 s:0275 e:000273 METHOD /home/user/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/irb/context.rb:459
c:0047 p:0033 s:0266 e:000265 BLOCK /home/user/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/irb.rb:541
c:0046 p:0024 s:0263 e:000262 METHOD /home/user/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/irb.rb:704

Hello @s0lar welcome to the forums.

Do you have the ports open for the application to be able to access the database ?
cluster.rb:415 this in the source attempts to connect to the cluster so apparently some problem while connecting to the database server - atleast it looks like that. (agreed that the error message was not very meaningful)
Did you try to write a very simple ruby app (without rails) and does that work ?
@avsej anything that you can think of ?

Sure, @AV25242 . With Irb it works good. Here is the log:

$ gem list | grep couchbase
couchbase (3.1.1 x86_64-linux)

$ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

$ irb -v
irb 1.2.6 (2020-09-14)

$ irb
2.7.2 :001 > require “couchbase”
[2021-05-27 18:51:27.279] [13449,13449] [info] 2ms, couchbase backend has been initialized: {:sdk=>“3.1.1”, :backend=>“1.5.0”, :build_timestamp=>“2021-04-08 16:29:43”, :revision=>“a79d098eb238b3883e49e1738c35167642e8834f”, :platform=>“Linux-4.15.0-66-generic”, :cpu=>“x86_64”, :cc=>“GNU 9.3.1”, :cxx=>“GNU 9.3.1”, :ruby=>“2.7.0”, :spdlog=>“1.8.1”, :asio=>“1.18.0”, :snappy=>“1.1.8”, :http_parser=>“2.9.4”, :openssl_headers=>“OpenSSL 1.1.1g FIPS 21 Apr 2020”, :openssl_runtime=>“OpenSSL 1.1.1g FIPS 21 Apr 2020”}
=> true

2.7.2 :002 > options = Couchbase::Cluster::ClusterOptions.new
=> #<Couchbase::Options::Cluster:0x0000000001d7a770 @authenticator=nil>

2.7.2 :003 > options.authenticate(“ADMIN”, “PASSWORD”)
=> #<Couchbase::PasswordAuthenticator:0x0000000001a7d3d8 @username=“ADMIN”, @password=“PASSWORD”, @allowed_sasl_mechanisms=[:scram_sha512, :scram_sha256, :scram_sha1]>

2.7.2 :004 > cluster = Couchbase::Cluster.connect(“couchbase://127.0.0.1”, options)
=> #Couchbase::Cluster:0x0000000001d74028

2.7.2 :005 > cluster.disconnect
=> nil