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

ruby-changes:65377

From: usa <ko1@a...>
Date: Tue, 2 Mar 2021 20:27:10 +0900 (JST)
Subject: [ruby-changes:65377] a175a30ab9 (ruby_2_6): merge revision(s) 5a79d8e0, 160511d8: [Backport #16925]

https://git.ruby-lang.org/ruby.git/commit/?id=a175a30ab9

From a175a30ab9d79b759fa17e71506caef896a4540e Mon Sep 17 00:00:00 2001
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Tue, 2 Mar 2021 11:26:58 +0000
Subject: merge revision(s) 5a79d8e0,160511d8: [Backport #16925]

	Fix error raised by Net::HTTPResponse#inflater if the block raises

	* See https://bugs.ruby-lang.org/issues/13882#note-6
	---
	 lib/net/http/response.rb                    |  5 ++-
	 spec/ruby/library/net/http/http/get_spec.rb | 67 +++++++++++++++++++++++++++++
	 2 files changed, 70 insertions(+), 2 deletions(-)

	Quarantine specs which fail frequently with CHECK_LEAKS=true

	---
	 spec/ruby/library/net/http/http/get_spec.rb | 2 ++
	 1 file changed, 2 insertions(+)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 lib/net/http/response.rb                    |  5 ++-
 spec/ruby/library/net/http/http/get_spec.rb | 69 +++++++++++++++++++++++++++++
 version.h                                   |  2 +-
 3 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb
index 6613298..ca0a6eb 100644
--- a/lib/net/http/response.rb
+++ b/lib/net/http/response.rb
@@ -262,12 +262,13 @@ class Net::HTTPResponse https://github.com/ruby/ruby/blob/trunk/lib/net/http/response.rb#L262
 
       begin
         yield inflate_body_io
+        success = true
       ensure
-        orig_err = $!
         begin
           inflate_body_io.finish
         rescue => err
-          raise orig_err || err
+          # Ignore #finish's error if there is an exception from yield
+          raise err if success
         end
       end
     when 'none', 'identity' then
diff --git a/spec/ruby/library/net/http/http/get_spec.rb b/spec/ruby/library/net/http/http/get_spec.rb
index 4b8af59..e6cd50f 100644
--- a/spec/ruby/library/net/http/http/get_spec.rb
+++ b/spec/ruby/library/net/http/http/get_spec.rb
@@ -24,3 +24,72 @@ describe "Net::HTTP.get when passed URI" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/net/http/http/get_spec.rb#L24
     end
   end
 end
+
+quarantine! do # These specs fail frequently with CHECK_LEAKS=true
+describe "Net::HTTP.get" do
+  describe "when reading gzipped contents" do
+    def start_threads
+      require 'zlib'
+
+      server = nil
+      server_thread = Thread.new do
+        server = TCPServer.new("127.0.0.1", 0)
+        begin
+          c = server.accept
+        ensure
+          server.close
+        end
+        c.print "HTTP/1.1 200\r\n"
+        c.print "Content-Type: text/plain\r\n"
+        c.print "Content-Encoding: gzip\r\n"
+        s = StringIO.new
+        z = Zlib::GzipWriter.new(s)
+        begin
+          z.write 'Hello World!'
+        ensure
+          z.close
+        end
+        c.print "Content-Length: #{s.length}\r\n\r\n"
+        # Write partial gzip content
+        c.write s.string.byteslice(0..-2)
+        c.flush
+        c
+      end
+      Thread.pass until server && server_thread.stop?
+
+      client_thread = Thread.new do
+        Thread.current.report_on_exception = false
+        Net::HTTP.get("127.0.0.1", '/', server.connect_address.ip_port)
+      end
+      Thread.pass until client_thread.stop?
+
+      [server_thread, client_thread]
+    end
+
+    it "propagates exceptions interrupting the thread and does not replace it with Zlib::BufError" do
+      my_exception = Class.new(RuntimeError)
+      server_thread, client_thread = start_threads
+      socket = server_thread.value
+      begin
+        client_thread.raise my_exception, "my exception"
+        -> { client_thread.value }.should raise_error(my_exception)
+      ensure
+        socket.close
+      end
+    end
+
+    ruby_version_is "2.8" do # https://bugs.ruby-lang.org/issues/13882#note-6
+      it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do
+        server_thread, client_thread = start_threads
+        socket = server_thread.value
+        begin
+          client_thread.kill
+          client_thread.value.should == nil
+        ensure
+          socket.close
+        end
+      end
+    end
+  end
+end
+end
diff --git a/version.h b/version.h
index 41acf52..60974d0 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.7"
 #define RUBY_RELEASE_DATE "2021-03-02"
-#define RUBY_PATCHLEVEL 168
+#define RUBY_PATCHLEVEL 169
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 3
-- 
cgit v1.1


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

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