THRIFT-1187. rb: nonblocking_server shutdown race under Ruby 1.9
authorBryan Duxbury <bryanduxbury@apache.org>
Wed, 1 Jun 2011 17:43:39 +0000 (17:43 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Wed, 1 Jun 2011 17:43:39 +0000 (17:43 +0000)
This patch fixes a shutdown error that occurs under ruby 1.9.2

Patch: Ilya Maykov

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1130242 13f79535-47bb-0310-9956-ffa450edef68

lib/rb/lib/thrift/server/nonblocking_server.rb

index fc57d14..911d6d5 100644 (file)
@@ -44,7 +44,13 @@ module Thrift
       begin
         loop do
           break if @server_transport.closed?
-          rd, = select([@server_transport], nil, nil, 0.1)
+          begin
+            rd, = select([@server_transport], nil, nil, 0.1)
+          rescue Errno::EBADF => e
+            # In Ruby 1.9, calling @server_transport.close in shutdown paths causes the select() to raise an
+            # Errno::EBADF. If this happens, ignore it and retry the loop.
+            next
+          end
           next if rd.nil?
           socket = @server_transport.accept
           @logger.debug "Accepted socket: #{socket.inspect}"