Thrift/Ruby: TSimpleServer closes its listen socket on an uncaught exception.

Submitted by William Morgan.
Approved by Kevin Clark.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665444 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/lib/thrift/server/tserver.rb b/lib/rb/lib/thrift/server/tserver.rb
index 9abfb30..d9ff621 100644
--- a/lib/rb/lib/thrift/server/tserver.rb
+++ b/lib/rb/lib/thrift/server/tserver.rb
@@ -32,23 +32,26 @@
   end
 
   def serve()
-    @serverTransport.listen()
-    while (true)
-      client = @serverTransport.accept()
-      trans = @transportFactory.getTransport(client)
-      prot = @protocolFactory.getProtocol(trans)
-      begin
-        while (true)
-          @processor.process(prot, prot)
+    begin
+      @serverTransport.listen()
+      while (true)
+        client = @serverTransport.accept()
+        trans = @transportFactory.getTransport(client)
+        prot = @protocolFactory.getProtocol(trans)
+        begin
+          while (true)
+            @processor.process(prot, prot)
+          end
+        rescue TTransportException, TProtocolException => ttx
+          #print ttx,"\n"
+        ensure
+          trans.close()
         end
-      rescue TTransportException, TProtocolException => ttx
-        #print ttx,"\n"
-      ensure
-        trans.close()
       end
+    ensure
+      @serverTransport.close()
     end
   end
-
 end
 
 begin