-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let Net::HTTP decompress the index instead of doing it manually #4081
Conversation
Looks like there is a strange bug in RuboCop, I didn't touch those lines: https://github.com/rubygems/rubygems/pull/4081/checks?check_run_id=1442980333 |
Could someone review this PR? |
2f4efb4
to
c3d4231
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eregon. I checked the net/http
code and I think I get it.
If "Accept-Encoding" is set, like we're doing, net/http
sets a flag to avoid handling decoding of the response (@decode_content = false
):
If it's not set, net/http
sets it to gzip
and sets the flag to handle it internally (@decode_content = true
):
Then when it comes to handling the response, it skips decompression if the @decode_content
flag is set, and also removes the Content-Encoding
header from the response:
So in that case, the block below where we handle it ourselves will be skipped since Content-Encoding
won't be set.
What I'm thinking is, since net/http
also handles availability of zlib
automatically, could we skip setting the Accept-Encoding
header altogether and also our handling of the response at
rubygems/bundler/lib/bundler/compact_index_client/updater.rb
Lines 60 to 62 in 184c84d
if response["Content-Encoding"] == "gzip" | |
content = Zlib::GzipReader.new(StringIO.new(content)).read | |
end |
?
I think we could do that, except maybe for And anyway, if zlib is not available, Net::HTTP would not set |
184c84d
to
2a4d3ac
Compare
I think we just run into this issue after upgrading to truffleruby 20.3: https://github.com/rubygems/rubygems/runs/1658684625? I rebased this and removed I could probably have gone all the way and also remove the require and the rescue |
Looks good to me. Yes, that should help with that error. We're also working on fixing this in general in TruffleRuby, but that will need to wait the 21.2 release probably. |
And thanks for rebasing and improving this PR! (I had it as a TODO but I have too many TODOs right now.) |
* Setting the Accept-Encoding header actually disables the automatic decompression as documented in Net::HTTP. https://github.com/ruby/ruby/blob/79a8ed07650dcbb36ec4b49a22596275e6c0fe23/lib/net/http/response.rb#L105-L107 https://github.com/ruby/ruby/blob/c5eb24349a4535948514fe765c3ddb0628d81004/lib/net/http/request.rb#L11-L12 * This is also more memory efficient as Net::HTTP decompresses chunk by chunk instead of having the entire compressed String in memory and also wrapped in a StringIO which is particularly inefficient. * See oracle/truffleruby#2127 (comment) for more details.
2a4d3ac
to
99e15a4
Compare
I think |
Even better 👍 |
Thanks @eregon! |
Let Net::HTTP decompress the index instead of doing it manually (cherry picked from commit a5e96ef)
decompression as documented in Net::HTTP.
https://github.com/ruby/ruby/blob/79a8ed07650dcbb36ec4b49a22596275e6c0fe23/lib/net/http/response.rb#L105-L107
https://github.com/ruby/ruby/blob/c5eb24349a4535948514fe765c3ddb0628d81004/lib/net/http/request.rb#L11-L12
by chunk instead of having the entire compressed String in memory
and also wrapped in a StringIO which is particularly inefficient.
bundle install --jobs 4 --retry 3
intermittently throws[ruby] WARNING OutOfMemoryError
oracle/truffleruby#2127 (comment)for more details.
As a result,
bundler
no longer usesstringio
, so the require for it can be removed avoid potential issues with thestringio
default gem. So this PR also closes #3860.Make sure the following tasks are checked