Ruby connection closed (DRb::DRbConnError)

888 views Asked by At

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
2

There are 2 answers

3
rebelshrug On

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?

0
Michael Yagudaev On

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).