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

ruby-changes:45238

From: shugo <ko1@a...>
Date: Thu, 12 Jan 2017 11:19:22 +0900 (JST)
Subject: [ruby-changes:45238] shugo:r57311 (trunk): lib/net/protocol.rb: preserve backtrace information

shugo	2017-01-12 11:19:17 +0900 (Thu, 12 Jan 2017)

  New Revision: 57311

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57311

  Log:
    lib/net/protocol.rb: preserve backtrace information
    
    BufferedIO#rbuf_fill should preserve backtrace information when raising
    EOFError.  Otherwise, users get confused when EOFError is leaked out from
    Net::SMTP etc.  [ruby-core:78550] [Bug #13018]

  Modified files:
    trunk/lib/net/protocol.rb
    trunk/test/net/smtp/test_smtp.rb
Index: test/net/smtp/test_smtp.rb
===================================================================
--- test/net/smtp/test_smtp.rb	(revision 57310)
+++ test/net/smtp/test_smtp.rb	(revision 57311)
@@ -157,6 +157,28 @@ module Net https://github.com/ruby/ruby/blob/trunk/test/net/smtp/test_smtp.rb#L157
       end
     end
 
+    def test_eof_error_backtrace
+      bug13018 = '[ruby-core:78550] [Bug #13018]'
+      servers = Socket.tcp_server_sockets("localhost", 0)
+      begin
+        sock = nil
+        Thread.start do
+          sock = accept(servers)
+          sock.close
+        end
+        smtp = Net::SMTP.new("localhost", servers[0].local_address.ip_port)
+        e = assert_raise(EOFError, bug13018) do
+          smtp.start do
+          end
+        end
+        assert_equal(EOFError, e.class, bug13018)
+        assert(e.backtrace.grep(%r"\bnet/smtp\.rb:").size > 0, bug13018)
+      ensure
+        sock.close if sock
+        servers.each(&:close)
+      end
+    end
+
     private
 
     def accept(servers)
Index: lib/net/protocol.rb
===================================================================
--- lib/net/protocol.rb	(revision 57310)
+++ lib/net/protocol.rb	(revision 57311)
@@ -181,8 +181,7 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L181
         @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
         # continue looping
       when nil
-        # callers do not care about backtrace, so avoid allocating for it
-        raise EOFError, 'end of file reached', []
+        raise EOFError, 'end of file reached'
       end while true
     end
 

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

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