[前][次][番号順一覧][スレッド一覧]

ruby-changes:15762

From: shugo <ko1@a...>
Date: Sun, 9 May 2010 08:28:53 +0900 (JST)
Subject: [ruby-changes:15762] Ruby:r27690 (trunk): * lib/net/imap.rb (disconnect): terminates @receiver_thread even if

shugo	2010-05-09 08:25:54 +0900 (Sun, 09 May 2010)

  New Revision: 27690

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27690

  Log:
    * lib/net/imap.rb (disconnect): terminates @receiver_thread even if
      @sock.shutdown raises an exception.  [ruby-dev:34881]

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/imap.rb
    trunk/test/net/imap/test_imap.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27689)
+++ ChangeLog	(revision 27690)
@@ -1,3 +1,8 @@
+Sun May  9 08:24:24 2010  Shugo Maeda  <shugo@r...>
+
+	* lib/net/imap.rb (disconnect): terminates @receiver_thread even if
+	  @sock.shutdown raises an exception.  [ruby-dev:34881]
+
 Sun May  9 06:15:21 2010  Kazuhiro NISHIYAMA  <zn@m...>
 
 	* io.c (nogvl_copy_stream_sendfile): ISO C90 forbids mixed
Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 27689)
+++ lib/net/imap.rb	(revision 27690)
@@ -307,9 +307,12 @@
         end
       rescue Errno::ENOTCONN
         # ignore `Errno::ENOTCONN: Socket is not connected' on some platforms.
+      rescue Exception => e
+        @receiver_thread.raise(e)
       end
       @receiver_thread.join
       @sock.close
+      raise e if e
     end
 
     # Returns true if disconnected from the server.
@@ -1012,7 +1015,10 @@
 
       @client_thread = Thread.current
       @receiver_thread = Thread.start {
-        receive_responses
+        begin
+          receive_responses
+        rescue Exception
+        end
       }
     end
 
Index: test/net/imap/test_imap.rb
===================================================================
--- test/net/imap/test_imap.rb	(revision 27689)
+++ test/net/imap/test_imap.rb	(revision 27690)
@@ -311,6 +311,43 @@
     end
   end
 
+  def test_exception_during_shutdown
+    server = TCPServer.new(0)
+    port = server.addr[1]
+    Thread.start do
+      begin
+        sock = server.accept
+        begin
+          sock.print("* OK test server\r\n")
+          sock.gets
+          sock.print("* BYE terminating connection\r\n")
+          sock.print("RUBY0001 OK LOGOUT completed\r\n")
+        ensure
+          sock.close
+        end
+      rescue
+      end
+    end
+    begin
+      begin
+        imap = Net::IMAP.new("localhost", :port => port)
+        imap.instance_eval do
+          def @sock.shutdown(*args)
+            super
+            raise "error"
+          end
+        end
+        imap.logout
+      ensure
+        assert_raise(RuntimeError) do
+          imap.disconnect
+        end
+      end
+    ensure
+      server.close
+    end
+  end
+
   private
 
   def imaps_test

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]