dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] rinda/ring.rb (make_socket): do not keep socket on failures
@ 2017-01-17  3:31 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-01-17  3:31 UTC (permalink / raw)
  To: spew

This prevents leaked FD warnings on test/rinda/test_rinda.rb
when testing on a machine without multicast support.
---
 lib/rinda/ring.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/rinda/ring.rb b/lib/rinda/ring.rb
index 9b3f13eb93..d82ecabfcc 100644
--- a/lib/rinda/ring.rb
+++ b/lib/rinda/ring.rb
@@ -135,7 +135,6 @@ def make_socket(address, interface_address=nil, multicast_interface=0)
 
       socket = Socket.new(addrinfo.pfamily, addrinfo.socktype,
                           addrinfo.protocol)
-      @sockets << socket
 
       if addrinfo.ipv4_multicast? or addrinfo.ipv6_multicast? then
         if Socket.const_defined?(:SO_REUSEPORT) then
@@ -166,6 +165,11 @@ def make_socket(address, interface_address=nil, multicast_interface=0)
       end
 
       socket
+    rescue
+      socket = socket.close if socket
+      raise
+    ensure
+      @sockets << socket if socket
     end
 
     ##
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-01-17  3:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-17  3:31 [PATCH] rinda/ring.rb (make_socket): do not keep socket on failures Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).