Ruby Issue Tracking System: Issueshttps://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-02-19T06:06:12ZRuby Issue Tracking System
Redmine Ruby master - Bug #4409 (Closed): DRb: discrepency between DRb.here? and DRb.uri leads to failure...https://redmine.ruby-lang.org/issues/44092011-02-19T06:06:12Znbondoux (Nicolas Bondoux)nbondoux@users.sourceforge.net
<p>=begin<br>
When a reference on a local object is sent back by a client to a server, it may not be recognised as a local object during marshalling:<br>
An object instance being sent as a reference is wrapped in a DRbObject built by make_proxy with DRbObject.new(obj); the DRbObject's uri will be the uri returned by DRb::uri.<br>
When this reference is sent back, DRbObject::_load checks if it matches uri of current server with DRb::here? method.</p>
<p>The problem is that DRb.here? checks that a DRbObject uri is the same as the uri which was used by current DRbServer at his creation, while DRb.uri will return an uri created from the local socket from current thread's connection.</p>
<p>So, when a DRbObject it sent back, it may not be recognized as referencing a local object</p>
<p>Fixing DRb.here? so that it compares with the uri returned by DRb.uri should be enough to quick fix this problem, and seems safe to me.<br>
(I call it a quick fix because I am sure that even with this change, it is possible to build some less realistics cases with the same kind of problem, due to the fact that a same reference may be valid or not depending which client sent it back ...)</p>
<p>Here is a very simple proof of concept:<br>
The server:</p>
<p>#!/usr/bin/ruby<br>
require 'drb'<br>
class A<br>
include DRb::DRbUndumped<br>
end</p>
<p>class TheServer<br>
include DRb::DRbUndumped<br>
def initialize<br>
<a class="user active user-mention" href="https://redmine.ruby-lang.org/users/52980">@A (A A)</a> = A.new<br>
end</p>
<p>def get_a<br>
<a class="user active user-mention" href="https://redmine.ruby-lang.org/users/52980">@A (A A)</a><br>
end</p>
<p>def is_a(iA)<br>
puts "inside is_a: current DRb.uri:#{DRb.uri}; iA.class = #{iA.class} #{iA.__drburi if DRb::DRbObject === iA}"<br>
@a.eql? iA<br>
end</p>
<p>def getToken<br>
retVal = @@token.clone<br>
@@token.inc<br>
return retVal<br>
end</p>
<p>end</p>
<p>theServer = TheServer.new<br>
DRb.start_service(nil,theServer)<br>
puts "DRb.uri just after start_service: #{DRb.uri}"<br>
DRb.thread.join</p>
<p>#############<br>
The client:</p>
<p>#!/usr/bin/ruby<br>
require 'drb'</p>
<p>theServer = DRb::DRbObject.new(nil,ARGV.shift)</p>
<p>a = theServer.get_a<br>
puts "a.__drburi == #{a.__drburi}"<br>
puts "theServer.is_a(a) == #{theServer.is_a(a)}"</p>
<p>#############<br>
the outputs:<br>
server side:<br>
DRb.uri just after start_service: druby://Venus:60106<br>
inside is_a: current DRb.uri:druby://127.0.0.1:60106; iA.class = DRb::DRbObject druby://127.0.0.1:60106</p>
<p>client side:<br>
a.__drburi == druby://127.0.0.1:60106<br>
theServer.is_a(a) == false</p>
<p>Cheers,</p>
<p>Nicolas<br>
=end</p>