rb: Wrap a semaphore around @serverTransport.close in NonblockingServer.shutdown
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@669020 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/server/nonblockingserver.rb b/lib/rb/lib/thrift/server/nonblockingserver.rb
index 283d5f5..054c4d7 100644
--- a/lib/rb/lib/thrift/server/nonblockingserver.rb
+++ b/lib/rb/lib/thrift/server/nonblockingserver.rb
@@ -15,6 +15,7 @@
@logger = logger
end
@shutdown_semaphore = Mutex.new
+ @transport_semaphore = Mutex.new
end
def serve
@@ -33,7 +34,9 @@
@logger.info "#{self} is shutting down, goodbye"
end
ensure
- @serverTransport.close
+ @transport_semaphore.synchronize do
+ @serverTransport.close
+ end
@io_manager.ensure_closed unless @io_manager.nil?
end
@@ -46,7 +49,9 @@
# but we can't change the order of operations here, so lets thread
shutdown_proc = lambda do
@io_manager.shutdown(timeout)
- @serverTransport.close # this will break the accept loop
+ @transport_semaphore.synchronize do
+ @serverTransport.close # this will break the accept loop
+ end
end
if block
shutdown_proc.call