Distributed Ruby method_missing NameError == boo (test case included)

C

curtis.schofield

Hi.

Distributed ruby seems to have issue with dispatch doen via
method_missing on the remote side. Is there a possible workaround for
this..


Here is a little test case that demonstrates the issue

#
# DRb method_missing test
#

class Tom
def bloop
puts "TOM GOES BLOOP"
return %w{h a t s a r e f u n}
end
def method_missing(method,*args)
puts "TOM :: method_missing #{method}"
end
end

class MMObject
def initialize()
@tom = Tom.new
end

def method_missing(method,*args)
@tom.send(method)
end
end
URI = 'druby://localhost:9000'
def server
mmObject = MMObject.new
DRb.start_service(URI, mmObject)
DRb.thread.join # Don't exit just yet!
end

def client
DRb.start_service()
mmObject = DRbObject.new(nil,URI)
mmObject.bloop
mmObject.whatever
end

require 'drb'

if __FILE__ == $0
begin
if not ARGV.nil? and ARGV.size == 1
send(ARGV[0])
else
raise "No Argument"
end
rescue
puts $!.message
puts "To Use this run with argument:
'server' to launch server instance
'client' to launch client instance
(which connects to server instance)
"
end
end
 
E

Eric Hodel

Hi.

Distributed ruby seems to have issue with dispatch doen via
method_missing on the remote side. Is there a possible workaround for
this..

This is by design, see #check_insecure_method. DRb only lets you
call public methods an object responds to.

DRb will let you call the method if you define #respond_to? correctly.

Beware the security implications of this.

require 'drb'

URI = 'druby://localhost:9000'

class MM
def method_missing(method, *args) puts "called #{method}" end
def respond_to?(method) method == :bloop end
end

case ARGV.first
when 'client'
DRb.start_service
mm = DRbObject.new nil, URI
mm.bloop
mm.whatever
when 'server'
DRb.start_service URI, MM.new
trap('INT') { DRb.thread.kill; exit }
DRb.thread.join
else
STDERR.puts "#{$0} client|server"
end
 
C

curtis.schofield

Beautiful. Thank for the complete info. I was thinking about how
respond_to must be playing a role, i think i can use this in a
resonably secure manner.

thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top