From: Massimiliano Mirra Date: 2001-12-04T23:51:47+09:00 Subject: [ruby-talk:27450] Checking objects in a drb net Yes, yes, DRb again, don't beat me, folks. I'm trying to make my app (an ICQ LAN-only clone) a bit real-world compliant, and must handle the case where a client is shutted down without first calling its logout method first (because of a kill signal, of a crash, or whatever). In other words the server has to handle refs to remote objects that stopped existing without telling it. Here is a snippet that reproduces the error. Server part: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require 'drb/drb' require 'drb/eq' class Server def initialize @users = [] end def register(attempting) @users.push(attempting) end def unregister(user) @users.delete(user) if @users.include?(user) end def user_list @users.collect{|user| user.name}.sort end end DRb.start_service('druby://localhost:9000', Server.new) gets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Client part: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require 'drb' class Client include DRbUndumped attr_reader :name def initialize(name) @name = name DRb.start_service @server = DRbObject.new(nil, 'druby://localhost:9000') end def login @server.register(self) end def logout @server.unregister(self) end def get_user_list puts @server.user_list end end name = ARGV.shift || 'joe' client = Client.new(name) client.login puts client.get_user_list # client.logout ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1) I start the server on a console. 2) I start a client on another console. It logs in by asking the server to register itself in @users. Then it queries the server for a list of logged users. It exits without having logged out. 3) I start another client. When it queries for logged users, the server cannot access to the former client referenced in @users and this is the result: $ ./client.rb foo (druby://localhost:9000) /usr/local/lib/site_ruby/1.6/drb/drb.rb:275:in `open': Connection refused - "connect(2)" (Errno::ECONNREFUSED) from (druby://localhost:9000) /usr/local/lib/site_ruby/1.6/drb/drb.rb:275:in `initialize' from (druby://localhost:9000) /usr/local/lib/site_ruby/1.6/drb/drb.rb:256:in `new' from (druby://localhost:9000) /usr/local/lib/site_ruby/1.6/drb/drb.rb:256:in `open' from (druby://localhost:9000) /usr/local/lib/site_ruby/1.6/drb/drb.rb:210:in `method_missing' from (druby://localhost:9000) ./server.rb:20:in `user_list' from (druby://localhost:9000) ./server.rb:20:in `collect' from (druby://localhost:9000) ./server.rb:20:in `user_list' from ./client.rb:24:in `get_user_list' from ./client.rb:32 Just checking for remote_object.nil? in Server does not do the trick, presumably because the reference is still there even if the object is not. Is there a way out? Massimiliano