Skip to content

Commit

Permalink
fix: use valid_delegator? and not reachable? before initiating a remo…
Browse files Browse the repository at this point in the history
…te operation

`reachable?` does `valid_delegator?` and then calls `ping` to check if the task
is actually alive. But (1) it requires a round-trip before actually accessing
the remote, and (2) is an illusion since the task could disappear between
reachable? and the actual remote operation.
  • Loading branch information
doudou committed Dec 14, 2024
1 parent c8146ca commit a006750
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/orocos/async/task_context_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def initialize(name,options=Hash.new)

on_port_reachable(false) do |name|
p = @ports[name]
if p && !p.reachable?
if p && !p.valid_delegator?
error_callback = Proc.new do |error|
p.emit_error(error)
end
Expand All @@ -517,7 +517,7 @@ def initialize(name,options=Hash.new)
end
on_property_reachable(false) do |name|
p = @properties[name]
if(p && !p.reachable?)
if(p && !p.valid_delegator?)
error_callback = Proc.new do |error|
p.emit_error(error)
end
Expand All @@ -528,7 +528,7 @@ def initialize(name,options=Hash.new)
end
on_attribute_reachable(false) do |name|
a = @attributes[name]
if(a && !a.reachable?)
if(a && !a.valid_delegator?)
error_callback = Proc.new do |error|
a.emit_error(error)
end
Expand Down Expand Up @@ -589,7 +589,8 @@ def property(name,options = Hash.new)
Orocos.warn "ignoring options: #{other_options}"
end

return p if !reachable? || p.reachable?
return p if !valid_delegator? || p.valid_delegator?

if options[:wait]
connect_property(p)
p.wait
Expand Down Expand Up @@ -618,7 +619,8 @@ def attribute(name,options = Hash.new)
Orocos.warn "ignoring options: #{other_options}"
end

return a if !reachable? || a.reachable?
return a if !valid_delegator? || a.valid_delegator?

if options[:wait]
connect_attribute(a)
a.wait
Expand All @@ -632,7 +634,7 @@ def attribute(name,options = Hash.new)

def port(name,options = Hash.new)
name = name.to_str
options,other_options = Kernel.filter_options options,:wait => @options[:wait]
options, other_options = Kernel.filter_options options,:wait => @options[:wait]
wait if options[:wait]

# support for subports
Expand Down Expand Up @@ -664,7 +666,7 @@ def port(name,options = Hash.new)
Orocos.warn "ignoring options: #{other_options}"
end

if reachable? && !p.reachable?
if valid_delegator? && !p.valid_delegator?
if options[:wait]
connect_port(p)
p.wait
Expand Down Expand Up @@ -841,8 +843,10 @@ def unreachable!(options = {:reconnect => false})
# all private methods must be thread safe
def connect_port(port)
return if port.reachable?

p = @mutex.synchronize do
return unless valid_delegator?

@delegator_obj.disable_emitting do
#called in the context of @delegator_obj
begin
Expand Down Expand Up @@ -928,7 +932,7 @@ def disconnect_properties
end

def respond_to_missing?(method_name, include_private = false)
(reachable? && @delegator_obj.respond_to?(method_name)) || super
(valid_delegator? && @delegator_obj.respond_to?(method_name)) || super
end

def method_missing(m,*args)
Expand Down

0 comments on commit a006750

Please sign in to comment.