Feature #4243 ยป 0001-DRb-should-not-forefully-close-connections-on-DRb-st.patch
| lib/drb/drb.rb | ||
|---|---|---|
|
# Stop this server.
|
||
|
def stop_service
|
||
|
DRb.remove_server(self)
|
||
|
if Thread.current['DRb'] && Thread.current['DRb']['server'] == self
|
||
|
Thread.current['DRb']['stop_service'] = true
|
||
|
else
|
||
|
@thread.kill.join
|
||
|
@thread.kill
|
||
|
|
||
|
# Check for foreign sub-threads
|
||
|
f = @grp.list.select{|t| t['DRb'].nil?}
|
||
|
$stderr.puts "DRb unknown threads: #{f.inspect}" if f.any?
|
||
|
|
||
|
# synchronous stop (without current and foreign threads)
|
||
|
while (@grp.list - [Thread.current] - f).size > 0
|
||
|
Thread.pass
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
end
|
||
|
private
|
||
|
def kill_sub_thread
|
||
|
Thread.new do
|
||
|
grp = ThreadGroup.new
|
||
|
grp.add(Thread.current)
|
||
|
list = @grp.list
|
||
|
while list.size > 0
|
||
|
list.each do |th|
|
||
|
th.kill if th.alive?
|
||
|
end
|
||
|
list = @grp.list
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def run
|
||
|
@stop_service = false
|
||
|
Thread.start do
|
||
|
begin
|
||
|
while true
|
||
| ... | ... | |
|
end
|
||
|
ensure
|
||
|
@protocol.close if @protocol
|
||
|
kill_sub_thread
|
||
|
@stop_service = true
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
end
|
||
|
client.send_reply(succ, result) rescue nil
|
||
|
ensure
|
||
|
client.close unless succ
|
||
|
if Thread.current['DRb']['stop_service']
|
||
|
Thread.new { stop_service }
|
||
|
if !succ or @stop_service
|
||
|
client.close
|
||
|
break
|
||
|
end
|
||
|
break unless succ
|
||
|
end
|
||
|
end
|
||
|
end
|
||