Skip to content

Commit e2e7440

Browse files
Vendor timeout in RubyGems too
1 parent 0d758e8 commit e2e7440

File tree

17 files changed

+257
-35
lines changed

17 files changed

+257
-35
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AllCops:
99
- bundler/tmp/**/*
1010
- lib/rubygems/resolver/molinillo/**/*
1111
- lib/rubygems/tsort/**/*
12+
- lib/rubygems/timeout/**/*
1213
- lib/rubygems/optparse/**/*
1314
- lib/rubygems/net-protocol/**/*
1415
- lib/rubygems/net-http/**/*

Manifest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA.pem
559559
lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem
560560
lib/rubygems/stub_specification.rb
561561
lib/rubygems/text.rb
562+
lib/rubygems/timeout.rb
563+
lib/rubygems/timeout/lib/timeout.rb
562564
lib/rubygems/tsort.rb
563565
lib/rubygems/tsort/.document
564566
lib/rubygems/tsort/LICENSE.txt

Rakefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ if File.exist?("tool/automatiek.rake")
232232
subsublib.prefix = "Gem"
233233
subsublib.vendor_lib = "lib/rubygems/net-protocol"
234234
subsublib.license_path = "License.txt"
235+
236+
subsublib.dependency("timeout") do |ssslib|
237+
ssslib.version = "v0.4.1"
238+
ssslib.download = { github: "https://github.com/ruby/timeout" }
239+
ssslib.namespace = "Timeout"
240+
ssslib.prefix = "Gem"
241+
ssslib.vendor_lib = "lib/rubygems/timeout"
242+
ssslib.license_path = "License.txt"
243+
end
244+
end
245+
246+
sublib.dependency("timeout") do |subsublib|
247+
subsublib.version = "v0.4.1"
248+
subsublib.download = { github: "https://github.com/ruby/timeout" }
249+
subsublib.namespace = "Timeout"
250+
subsublib.prefix = "Gem"
251+
subsublib.vendor_lib = "lib/rubygems/timeout"
252+
subsublib.license_path = "License.txt"
235253
end
236254
end
237255
end

lib/rubygems/command_manager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def self.reset
106106
# Register all the subcommands supported by the gem command.
107107

108108
def initialize
109-
require "timeout"
109+
require_relative "timeout"
110110
@commands = {}
111111

112112
BUILTIN_COMMANDS.each do |name|
@@ -149,7 +149,7 @@ def command_names
149149

150150
def run(args, build_args=nil)
151151
process_args(args, build_args)
152-
rescue StandardError, Timeout::Error => ex
152+
rescue StandardError, Gem::Timeout::Error => ex
153153
if ex.respond_to?(:detailed_message)
154154
msg = ex.detailed_message(highlight: false).sub(/\A(.*?)(?: \(.+?\))/) { $1 }
155155
else

lib/rubygems/gemcutter_utilities/webauthn_poller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def self.poll_thread(options, host, webauthn_url, credentials)
3737
thread.abort_on_exception = true
3838
thread.report_on_exception = false
3939
thread[:otp] = new(options, host).poll_for_otp(webauthn_url, credentials)
40-
rescue Gem::WebauthnVerificationError, Timeout::Error => e
40+
rescue Gem::WebauthnVerificationError, Gem::Timeout::Error => e
4141
thread[:error] = e
4242
end
4343
end
4444

4545
def poll_for_otp(webauthn_url, credentials)
46-
Timeout.timeout(TIMEOUT_IN_SECONDS) do
46+
Gem::Timeout.timeout(TIMEOUT_IN_SECONDS) do
4747
loop do
4848
response = webauthn_verification_poll_response(webauthn_url, credentials)
4949
raise Gem::WebauthnVerificationError, response.message unless response.is_a?(Gem::Net::HTTPSuccess)

lib/rubygems/net-http/lib/net/http.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ def ipaddr=(addr)
13081308
# Sets the maximum number of times to retry an idempotent request in case of
13091309
# \Gem::Net::ReadTimeout, IOError, EOFError, Errno::ECONNRESET,
13101310
# Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError,
1311-
# Timeout::Error.
1311+
# Gem::Timeout::Error.
13121312
# The initial value is 1.
13131313
#
13141314
# Argument +retries+ must be a non-negative numeric value:
@@ -1598,7 +1598,7 @@ def connect
15981598
end
15991599

16001600
debug "opening connection to #{conn_addr}:#{conn_port}..."
1601-
s = Timeout.timeout(@open_timeout, Gem::Net::OpenTimeout) {
1601+
s = Gem::Timeout.timeout(@open_timeout, Gem::Net::OpenTimeout) {
16021602
begin
16031603
TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
16041604
rescue => e
@@ -2358,7 +2358,7 @@ def transport_request(req)
23582358
Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, Errno::ETIMEDOUT,
23592359
# avoid a dependency on OpenSSL
23602360
defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
2361-
Timeout::Error => exception
2361+
Gem::Timeout::Error => exception
23622362
if count < max_retries && IDEMPOTENT_METHODS_.include?(req.method)
23632363
count += 1
23642364
@socket.close if @socket

lib/rubygems/net-http/lib/net/http/responses.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class HTTPProxyAuthenticationRequired < HTTPClientError
589589
HAS_BODY = true
590590
end
591591

592-
# Response class for <tt>Request Timeout</tt> responses (status code 408).
592+
# Response class for <tt>Request Gem::Timeout</tt> responses (status code 408).
593593
#
594594
# The server timed out waiting for the request.
595595
#
@@ -980,7 +980,7 @@ class HTTPServiceUnavailable < HTTPServerError
980980
HAS_BODY = true
981981
end
982982

983-
# Response class for <tt>Gateway Timeout</tt> responses (status code 504).
983+
# Response class for <tt>Gateway Gem::Timeout</tt> responses (status code 504).
984984
#
985985
# The server was acting as a gateway or proxy
986986
# and did not receive a timely response from the upstream server.

lib/rubygems/net-protocol/lib/net/protocol.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#
2121

2222
require 'socket'
23-
require 'timeout'
23+
require_relative '../../../timeout/lib/timeout'
2424
require 'io/wait'
2525

2626
module Gem::Net # :nodoc:
@@ -68,16 +68,16 @@ class ProtoRetriableError < ProtocolError; end
6868
ProtocRetryError = ProtoRetriableError
6969

7070
##
71-
# OpenTimeout, a subclass of Timeout::Error, is raised if a connection cannot
71+
# OpenTimeout, a subclass of Gem::Timeout::Error, is raised if a connection cannot
7272
# be created within the open_timeout.
7373

74-
class OpenTimeout < Timeout::Error; end
74+
class OpenTimeout < Gem::Timeout::Error; end
7575

7676
##
77-
# ReadTimeout, a subclass of Timeout::Error, is raised if a chunk of the
77+
# ReadTimeout, a subclass of Gem::Timeout::Error, is raised if a chunk of the
7878
# response cannot be read within the read_timeout.
7979

80-
class ReadTimeout < Timeout::Error
80+
class ReadTimeout < Gem::Timeout::Error
8181
def initialize(io = nil)
8282
@io = io
8383
end
@@ -93,10 +93,10 @@ def message
9393
end
9494

9595
##
96-
# WriteTimeout, a subclass of Timeout::Error, is raised if a chunk of the
96+
# WriteTimeout, a subclass of Gem::Timeout::Error, is raised if a chunk of the
9797
# response cannot be written within the write_timeout. Not raised on Windows.
9898

99-
class WriteTimeout < Timeout::Error
99+
class WriteTimeout < Gem::Timeout::Error
100100
def initialize(io = nil)
101101
@io = io
102102
end

lib/rubygems/remote_fetcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def fetch_path(uri, mtime = nil, head = false)
261261
end
262262

263263
data
264-
rescue Timeout::Error, IOError, SocketError, SystemCallError,
264+
rescue Gem::Timeout::Error, IOError, SocketError, SystemCallError,
265265
*(OpenSSL::SSL::SSLError if Gem::HAVE_OPENSSL) => e
266266
raise FetchError.new("#{e.class}: #{e}", uri)
267267
end

lib/rubygems/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def perform_request(request) # :nodoc:
244244
# HACK: work around EOFError bug in Gem::Net::HTTP
245245
# NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
246246
# to install gems.
247-
rescue EOFError, Timeout::Error,
247+
rescue EOFError, Gem::Timeout::Error,
248248
Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
249249

250250
requests = @requests[connection.object_id]

0 commit comments

Comments
 (0)