diff --git a/lib/rb/lib/thrift/server/nonblocking_server.rb b/lib/rb/lib/thrift/server/nonblocking_server.rb
index <HASH>..<HASH> 100644
--- a/lib/rb/lib/thrift/server/nonblocking_server.rb
+++ b/lib/rb/lib/thrift/server/nonblocking_server.rb
@@ -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}"
THRIFT-<I>. rb: nonblocking_server shutdown race under Ruby <I>

This patch fixes a shutdown error that occurs under ruby <I>

Patch: Ilya Maykov

git-svn-id: <URL>