48

I have the following test code:

def loop_bucket_gets
    bucket = Couchbase::Bucket.new({:node_list => ['xxx.xxx.xxx.xxx:8091', 'yyy.yyy.yyy.yyy:8091'],
                                    :bucket => 'Foo',
                                    :pool => 'default',
                                    :expires_in => 1.day,
                                    :default_format => :marshal,
                                    :key_prefix => '_foo'
                                   })

    i = 0
    loop do
      begin
        i += 1
        bucket.get "ABC#{i}"
      rescue ::Couchbase::Error::Base => e
        nil
      end
    end
  end

When I execute this in the Rails console the memory leaks.

I'm using:

  • couchbase 1.3.10 gem
  • libcouchbase 2.4.3

I created an issue at https://www.couchbase.com/issues/browse/RCBC-187

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Lazarus Lazaridis
  • 5,803
  • 2
  • 21
  • 35

1 Answers1

-1

There is no terminating condition in your loop so it's going to run forever and cause the memory issue you mentioned. You should add a relevant break condition in your loop and test if it resolves the issue.

def loop_bucket_gets
    bucket = Couchbase::Bucket.new({:node_list => ['xxx.xxx.xxx.xxx:8091', 'yyy.yyy.yyy.yyy:8091'],
                                    :bucket => 'Foo',
                                    :pool => 'default',
                                    :expires_in => 1.day,
                                    :default_format => :marshal,
                                    :key_prefix => '_foo'
                                   })

    i = 0
    loop do
      begin
        i += 1
        bucket.get "ABC#{i}"
        break if YOUR_TERMINATING_CONDITION
      rescue ::Couchbase::Error::Base => e
        nil
      end
    end
  end
Sachin Singh
  • 993
  • 8
  • 16