Project

General

Profile

Bug #12702 ยป drb_block_error.rb

code to reproduce the problem - djellemah (John Anderson), 08/24/2016 11:45 AM

 
1
require 'drb'
2

    
3
class Front
4
  include DRbUndumped
5

    
6
  def remote_method
7
    return :no_block unless block_given?
8
    yield :with_block
9
    :last
10
  end
11
end
12

    
13
URI = 'druby://localhost:6947'
14

    
15
def thread_server
16
  DRb.start_service URI, Front.new
17
end
18

    
19
def process_server
20
  server_pid = fork do
21
    server = DRb.start_service URI, Front.new
22
    server.thread.join
23
  end
24

    
25
  at_exit{ Process.kill 'TERM', server_pid }
26
end
27

    
28
# in-process works OK
29
thread_server
30

    
31
# out-of-process fails
32
# process_server
33

    
34
# give server time to start listening, just to show it's not server startup
35
# delay causing the error. Not necessary otherwise.
36
sleep 0.5
37

    
38
proxy = DRbObject.new_with_uri URI
39
values = []
40

    
41
# This always succeeds
42
values << proxy.remote_method
43

    
44
# calling the method with a block raises
45
#   DRb::DRbConnError: DRb::DRbServerNotFound
46
# with out-of-process server.
47
#
48
# But works OK with in-process server.
49
values << (proxy.remote_method{|a| values << a} rescue $!.message)
50

    
51
# should be {:values=>[:no_block, :with_block, :last]}
52
p values: values
53

    
54
# applies to ruby-2.3.1 and ruby-2.4.0dev (2016-08-24 trunk 55999)
55
#
56
# The problem starts in DRbObject#method_missing where
57
# the code following DRb.here? is used for the in-process case which works.
58

    
59
# But the code in the block for
60

    
61
#   succ, result = self.class.with_friend(@uri) do
62

    
63
# is used for the out-of-process case. Here, DrbMessage#send_request fails
64
# because b is a Proc, and in DrbMessage#dump the call to make_proxy fails
65
# because DRbObject.new(b) fails.