Forum: Ruby Rinda::RingFinger.primary broken on 1.9?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aa012716306af231efe9022c2b9205a3?d=identicon&s=25 Hubert Lee (hubert_l)
on 2012-05-07 19:04
The following code correctly errors (with RingNotFound) on Ruby 1.8.6
and 1.8.7, but hangs forever on 1.9.2 and 1.9.3:

  require 'rinda/ring'
  DRb.start_service
  Rinda::RingFinger.primary

This behavior is consistent on Windows 7 and Linux (both RH 5.6 and
CentOS 5.6). Anyone have an idea what's going on?

Thanks,
Hubert
399151d12a6a14d1205fdff284213abe?d=identicon&s=25 SEKI Masatoshi (Guest)
on 2012-05-08 07:33
(Received via mailing list)
Hi, Hubert-san.

Thank you for the report.
It's my bug.

Please try this patch:

require 'rinda/ring'

module Rinda
  class RingFinger
    def lookup_ring_any(timeout=5)
      queue = Queue.new

      th = Thread.new do
  self.lookup_ring(timeout) do |ts|
    queue.push(ts)
  end
  queue.push(nil)
      end

      @primary = queue.pop
      raise('RingNotFound') if @primary.nil?
      while it = queue.pop
        @rings.push(it)
      end

      @primary
    end
  end
end


DRb.start_service
Rinda::RingFinger.primary
399151d12a6a14d1205fdff284213abe?d=identicon&s=25 SEKI Masatoshi (Guest)
on 2012-05-08 21:46
(Received via mailing list)
Hi, Hubert-san.

It's a bug.
I fixed it in svn.

Index: lib/rinda/ring.rb
===================================================================
--- lib/rinda/ring.rb  (revision 35596)
+++ lib/rinda/ring.rb  (working copy)
@@ -203,13 +203,17 @@
           queue.push(ts)
         end
         queue.push(nil)
+      end
+
+      @primary = queue.pop
+      raise('RingNotFound') if @primary.nil?
+
+      Thread.new do
         while it = queue.pop
           @rings.push(it)
         end
       end

-      @primary = queue.pop
-      raise('RingNotFound') if @primary.nil?
       @primary
     end
Aa012716306af231efe9022c2b9205a3?d=identicon&s=25 Hubert Lee (hubert_l)
on 2012-05-08 23:51
That fixes it! Thanks!

Regards,
Hubert
This topic is locked and can not be replied to.