1

I am experiencing a really weird behaviour with Ruby DRb or maybe the problem is dbm. I am using the dbm database with a server, and a client that makes the requests via DRb.

Here's the method with the problem (the database connection is ok) and it is in the server:

def get id
    obj = nil
    db = DBM.open @name
    obj = db[id.to_s]
    db.close
    return obj
end

This line obj = db[id.to_s] returns the error connection closed (DRb::DRbConnError) in the client side.

The thing is if I do this obj = db['1'] it works just fine ('1' is a key in the dbm). Why does this happen? What is wrong with id? Here's the call in the client side:

DRb.start_service
r = DRbObject.new_with_uri(SERVER_URI)
puts r.get '1'

Why am I getting this error? The same thing happens with this method:

def delete id
    db = DBM.open @name
    db.delete id
    db.close
end
dabadaba
  • 9,064
  • 21
  • 85
  • 155

2 Answers2

0

In /lib/drb/drb.rb, it looks like the connection closed error is raised when sz.nil? and str.nil.

raise(DRbConnError, 'connection closed') if sz.nil?

raise(DRbConnError, 'connection closed') if str.nil?

what does obj = db[id.to_s] return?

the_storyteller
  • 2,335
  • 1
  • 26
  • 37
rebelshrug
  • 682
  • 7
  • 10
  • I also tried `obj = db[id.to_s]` before and I got the exact same error than just `id`, which is a string in the client side anyway. It doesn't return anything, just raises the error and the server stops – dabadaba Dec 04 '14 at 15:59
  • In the get_id method, if you add a `p obj` between `obj = db[id.to_s]` and `db.close`, what does it return? – rebelshrug Dec 04 '14 at 16:17
  • nothing, the server crashes in the line `obj = db[id.to_s]` so anything after it won't happen – dabadaba Dec 05 '14 at 13:38
0

Try patching your ruby to give you a little bit more details about the error on the server side of the relationship.

See: https://github.com/ruby/ruby/pull/1260.

In my case it was an issue with declaring a safe_level and then some of the code I called ended up violating the security (i.e. making a "dangerous call).

Michael Yagudaev
  • 6,049
  • 3
  • 48
  • 53