net-http-persistent 4.0.5 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 182064ce89718e66d95177021a7005adeb6e1d4299925e90fc6ac2a537dc533d
4
- data.tar.gz: ef7588300c587a1f71e49496ed6131acdf3cad110fa6653acab3779f5f01e3ee
3
+ metadata.gz: d13ea72f6eaa649a5afa7d75edc0322ae379aa6b58e96df1c4ce8f968aae4e58
4
+ data.tar.gz: 4a27f74cede0dde8f689d7bf3991bf623ed8126fe58a0cedc3e21ddfd82b3562
5
5
  SHA512:
6
- metadata.gz: 14c95c55ea8c89616d13917ba1fb9b05253181fd7007cf5aa03ab03c8e9987e8d4dc936b21481bf37f810df5931994ea6e5dc2eb6c259ab6591f2cfa75bff24f
7
- data.tar.gz: e7560d360ac6b20b750a19f6b84c7e5f8656e44962fbb8223ae1295e18dea513456df99c268fa06c2909b9c7e1c4e96655b7055432032d1044187ce07a2ba40b
6
+ metadata.gz: cb6f7f934a1a1e0baea5821599d3acde60ae304d7e5bbb8b4052f293e1007fe019b569ba049dffbbce3fdba161cd89e2bcd5d772eabe71097f720013dfef5688
7
+ data.tar.gz: c0b5e958e4f5f3357a3d7d820a9d44c3fc1ee6f4abf58e39d59afa0eebf28cdd0563161dc7994b0bbb1adc03725b863703892be38b34efac6d9c977be944505d
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 4.0.6 / 2024-12-04
2
+
3
+ Bug fixes:
4
+
5
+ * Allow ConnectionPool exceptions from checkout to bubble up to caller.
6
+
1
7
  === 4.0.5 / 2024-12-04
2
8
 
3
9
  Bug fixes:
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = net-http-persistent
2
2
 
3
3
  home :: https://github.com/drbrain/net-http-persistent
4
- rdoc :: https://rdoc.info/gems/net-http-persistent
4
+ rdoc :: https://rubydoc.info/gems/net-http-persistent
5
5
 
6
6
  == DESCRIPTION:
7
7
 
@@ -4,7 +4,7 @@ class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
4
4
  attr_reader :key # :nodoc:
5
5
 
6
6
  def initialize(options = {}, &block)
7
- super
7
+ super(**options, &block)
8
8
 
9
9
  @available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
10
10
  @key = "current-#{@available.object_id}"
@@ -1,5 +1,10 @@
1
1
  class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:
2
2
 
3
+ ##
4
+ # Detects if ConnectionPool 3.0+ is being used (needed for TimedStack subclass compatibility)
5
+
6
+ CP_USES_KEYWORD_ARGS = Gem::Version.new(ConnectionPool::VERSION) >= Gem::Version.new('3.0.0') # :nodoc:
7
+
3
8
  ##
4
9
  # Returns a new hash that has arrays for keys
5
10
  #
@@ -11,7 +16,11 @@ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nod
11
16
  end
12
17
 
13
18
  def initialize(size = 0, &block)
14
- super
19
+ if CP_USES_KEYWORD_ARGS
20
+ super(size: size, &block)
21
+ else
22
+ super(size, &block)
23
+ end
15
24
 
16
25
  @enqueued = 0
17
26
  @ques = self.class.hash_of_arrays
@@ -63,7 +72,8 @@ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nod
63
72
  if @created >= @max && @enqueued >= 1
64
73
  oldest, = @lru.first
65
74
  @lru.delete oldest
66
- @ques[oldest].pop
75
+ connection = @ques[oldest].pop
76
+ connection.close if connection.respond_to?(:close)
67
77
 
68
78
  @created -= 1
69
79
  end
@@ -47,9 +47,8 @@ autoload :OpenSSL, 'openssl'
47
47
  # # perform the POST, the URI is always required
48
48
  # response http.request post_uri, post
49
49
  #
50
- # Note that for GET, HEAD and other requests that do not have a body you want
51
- # to use URI#request_uri not URI#path. The request_uri contains the query
52
- # params which are sent in the body for other requests.
50
+ # Note that for GET, HEAD and other requests that do not have a body,
51
+ # it uses URI#request_uri as default to send query params
53
52
  #
54
53
  # == TLS/SSL
55
54
  #
@@ -182,7 +181,7 @@ class Net::HTTP::Persistent
182
181
  ##
183
182
  # The version of Net::HTTP::Persistent you are using
184
183
 
185
- VERSION = '4.0.5'
184
+ VERSION = '4.0.7'
186
185
 
187
186
  ##
188
187
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -477,6 +476,13 @@ class Net::HTTP::Persistent
477
476
 
478
477
  attr_reader :verify_hostname
479
478
 
479
+
480
+ ##
481
+ # Sets whether to ignore end-of-file when reading a response body
482
+ # with Content-Length headers.
483
+
484
+ attr_accessor :ignore_eof
485
+
480
486
  ##
481
487
  # Creates a new Net::HTTP::Persistent.
482
488
  #
@@ -516,6 +522,7 @@ class Net::HTTP::Persistent
516
522
  @max_retries = 1
517
523
  @socket_options = []
518
524
  @ssl_generation = 0 # incremented when SSL session variables change
525
+ @ignore_eof = nil
519
526
 
520
527
  @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
521
528
  Socket.const_defined? :TCP_NODELAY
@@ -631,47 +638,50 @@ class Net::HTTP::Persistent
631
638
 
632
639
  connection = @pool.checkout net_http_args
633
640
 
634
- http = connection.http
641
+ begin
642
+ http = connection.http
635
643
 
636
- connection.ressl @ssl_generation if
637
- connection.ssl_generation != @ssl_generation
644
+ connection.ressl @ssl_generation if
645
+ connection.ssl_generation != @ssl_generation
638
646
 
639
- if not http.started? then
640
- ssl http if use_ssl
641
- start http
642
- elsif expired? connection then
643
- reset connection
644
- end
647
+ if not http.started? then
648
+ ssl http if use_ssl
649
+ start http
650
+ elsif expired? connection then
651
+ reset connection
652
+ end
645
653
 
646
- http.keep_alive_timeout = @idle_timeout if @idle_timeout
647
- http.max_retries = @max_retries if http.respond_to?(:max_retries=)
648
- http.read_timeout = @read_timeout if @read_timeout
649
- http.write_timeout = @write_timeout if
650
- @write_timeout && http.respond_to?(:write_timeout=)
654
+ http.ignore_eof = @ignore_eof if @ignore_eof
655
+ http.keep_alive_timeout = @idle_timeout if @idle_timeout
656
+ http.max_retries = @max_retries if http.respond_to?(:max_retries=)
657
+ http.read_timeout = @read_timeout if @read_timeout
658
+ http.write_timeout = @write_timeout if
659
+ @write_timeout && http.respond_to?(:write_timeout=)
660
+
661
+ return yield connection
662
+ rescue Errno::ECONNREFUSED
663
+ if http.proxy?
664
+ address = http.proxy_address
665
+ port = http.proxy_port
666
+ else
667
+ address = http.address
668
+ port = http.port
669
+ end
651
670
 
652
- return yield connection
653
- rescue Errno::ECONNREFUSED
654
- if http.proxy?
655
- address = http.proxy_address
656
- port = http.proxy_port
657
- else
658
- address = http.address
659
- port = http.port
660
- end
671
+ raise Error, "connection refused: #{address}:#{port}"
672
+ rescue Errno::EHOSTDOWN
673
+ if http.proxy?
674
+ address = http.proxy_address
675
+ port = http.proxy_port
676
+ else
677
+ address = http.address
678
+ port = http.port
679
+ end
661
680
 
662
- raise Error, "connection refused: #{address}:#{port}"
663
- rescue Errno::EHOSTDOWN
664
- if http.proxy?
665
- address = http.proxy_address
666
- port = http.proxy_port
667
- else
668
- address = http.address
669
- port = http.port
681
+ raise Error, "host down: #{address}:#{port}"
682
+ ensure
683
+ @pool.checkin net_http_args
670
684
  end
671
-
672
- raise Error, "host down: #{address}:#{port}"
673
- ensure
674
- @pool.checkin net_http_args
675
685
  end
676
686
 
677
687
  ##
@@ -996,7 +1006,8 @@ class Net::HTTP::Persistent
996
1006
  end
997
1007
 
998
1008
  ##
999
- # Shuts down all connections
1009
+ # Shuts down all connections. Attempting to checkout a connection after
1010
+ # shutdown will raise an error.
1000
1011
  #
1001
1012
  # *NOTE*: Calling shutdown for can be dangerous!
1002
1013
  #
@@ -1007,6 +1018,17 @@ class Net::HTTP::Persistent
1007
1018
  @pool.shutdown { |http| http.finish }
1008
1019
  end
1009
1020
 
1021
+ ##
1022
+ # Discard all existing connections. Subsequent checkouts will create
1023
+ # new connections as needed.
1024
+ #
1025
+ # If any thread is still using a connection it may cause an error! Call
1026
+ # #reload when you are completely done making requests!
1027
+
1028
+ def reload
1029
+ @pool.reload { |http| http.finish }
1030
+ end
1031
+
1010
1032
  ##
1011
1033
  # Enables SSL on +connection+
1012
1034
 
@@ -80,7 +80,7 @@ class TestNetHttpPersistent < Minitest::Test
80
80
  :read_timeout, :open_timeout, :keep_alive_timeout
81
81
  attr_accessor :ciphers, :ssl_timeout, :ssl_version, :min_version,
82
82
  :max_version, :verify_depth, :verify_mode, :cert_store,
83
- :ca_file, :ca_path, :cert, :key
83
+ :ca_file, :ca_path, :cert, :key, :ignore_eof
84
84
  attr_reader :req, :debug_output
85
85
  def initialize
86
86
  @started, @finished = 0, 0
@@ -280,6 +280,16 @@ class TestNetHttpPersistent < Minitest::Test
280
280
  assert_same used, stored
281
281
  end
282
282
 
283
+ def test_connection_for_exhaustion
284
+ @http = Net::HTTP::Persistent.new pool_size: 0
285
+
286
+ assert_raises Timeout::Error do
287
+ @http.connection_for @uri do |c|
288
+ assert_same nil, c
289
+ end
290
+ end
291
+ end
292
+
283
293
  def test_connection_for_cached
284
294
  cached = basic_connection
285
295
  cached.http.start
@@ -993,7 +1003,7 @@ class TestNetHttpPersistent < Minitest::Test
993
1003
 
994
1004
  # There's some roounding issue on jruby preventing this from passing
995
1005
  unless RUBY_PLATFORM == "java"
996
- assert_in_delta Time.now, c.last_use
1006
+ assert_in_delta Time.now, c.last_use, 0.003
997
1007
  end
998
1008
 
999
1009
  assert_equal 1, c.requests
@@ -1255,6 +1265,17 @@ class TestNetHttpPersistent < Minitest::Test
1255
1265
  refute c2.http.finished?, 'present generation connection must not be finished'
1256
1266
  end
1257
1267
 
1268
+ def test_reload
1269
+ c = connection
1270
+
1271
+ @http.reload
1272
+
1273
+ c2 = connection
1274
+
1275
+ assert c.http.finished?, 'last-generation connection must be finished'
1276
+ refute c2.http.finished?, 'present generation connection must not be finished'
1277
+ end
1278
+
1258
1279
  def test_ssl
1259
1280
  skip 'OpenSSL is missing' unless HAVE_OPENSSL
1260
1281
 
@@ -1509,4 +1530,22 @@ class TestNetHttpPersistent < Minitest::Test
1509
1530
  connection.close
1510
1531
  end
1511
1532
  end
1533
+
1534
+ def test_ignore_eof
1535
+ @http.ignore_eof = true
1536
+
1537
+ connection
1538
+
1539
+ @http.connection_for @uri do |c|
1540
+ assert c.http.ignore_eof
1541
+ end
1542
+
1543
+ @http.ignore_eof = false
1544
+
1545
+ connection
1546
+
1547
+ @http.connection_for @uri do |c|
1548
+ assert !c.http.ignore_eof
1549
+ end
1550
+ end
1512
1551
  end
@@ -4,10 +4,15 @@ require 'net/http/persistent'
4
4
  class TestNetHttpPersistentTimedStackMulti < Minitest::Test
5
5
 
6
6
  class Connection
7
- attr_reader :host
7
+ attr_reader :host, :closed
8
8
 
9
9
  def initialize(host)
10
10
  @host = host
11
+ @closed = false
12
+ end
13
+
14
+ def close
15
+ @closed = true
11
16
  end
12
17
  end
13
18
 
@@ -24,7 +29,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
24
29
 
25
30
  assert_empty stack
26
31
 
27
- stack.push connection_args: popped
32
+ stack.push popped, connection_args: 'default'
28
33
 
29
34
  refute_empty stack
30
35
  end
@@ -38,7 +43,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
38
43
 
39
44
  assert_equal 0, stack.length
40
45
 
41
- stack.push connection_args: popped
46
+ stack.push popped, connection_args: 'default'
42
47
 
43
48
  assert_equal 1, stack.length
44
49
  end
@@ -57,7 +62,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
57
62
  @stack.pop timeout: 0
58
63
  end
59
64
 
60
- assert_match 'Waited 0 sec', e.message
65
+ assert_includes e.message, 'Waited 0 sec'
61
66
  end
62
67
 
63
68
  def test_pop_full
@@ -69,6 +74,18 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
69
74
  assert_empty stack
70
75
  end
71
76
 
77
+ def test_pop_closes_extra_connections
78
+ stack = Net::HTTP::Persistent::TimedStackMulti.new(1) { |host| Connection.new(host) }
79
+
80
+ a_conn = stack.pop connection_args: 'a.example'
81
+ stack.push a_conn, connection_args: 'a.example'
82
+
83
+ b_conn = stack.pop connection_args: 'b.example'
84
+
85
+ assert a_conn.closed
86
+ refute b_conn.closed
87
+ end
88
+
72
89
  def test_pop_wait
73
90
  thread = Thread.start do
74
91
  @stack.pop
@@ -96,7 +113,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
96
113
 
97
114
  conn = stack.pop
98
115
 
99
- stack.push connection_args: conn
116
+ stack.push conn, connection_args: 'default'
100
117
 
101
118
  refute_empty stack
102
119
  end
@@ -108,14 +125,16 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
108
125
  called << object
109
126
  end
110
127
 
111
- @stack.push connection_args: Object.new
128
+ obj = Object.new
129
+ @stack.push obj, connection_args: 'default'
112
130
 
113
131
  refute_empty called
114
132
  assert_empty @stack
115
133
  end
116
134
 
117
135
  def test_shutdown
118
- @stack.push connection_args: Object.new
136
+ obj = Object.new
137
+ @stack.push obj, connection_args: 'default'
119
138
 
120
139
  called = []
121
140
 
metadata CHANGED
@@ -1,29 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-persistent
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: connection_pool
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.2.4
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 2.2.4
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '4'
32
+ - !ruby/object:Gem::Dependency
33
+ name: cgi
15
34
  requirement: !ruby/object:Gem::Requirement
16
35
  requirements:
17
36
  - - "~>"
18
37
  - !ruby/object:Gem::Version
19
- version: '2.2'
38
+ version: 0.5.1
20
39
  type: :runtime
21
40
  prerelease: false
22
41
  version_requirements: !ruby/object:Gem::Requirement
23
42
  requirements:
24
43
  - - "~>"
25
44
  - !ruby/object:Gem::Version
26
- version: '2.2'
45
+ version: 0.5.1
27
46
  description: |-
28
47
  Manages persistent connections using Net::HTTP including a thread pool for
29
48
  connecting to multiple hosts.
@@ -63,7 +82,6 @@ licenses:
63
82
  - MIT
64
83
  metadata:
65
84
  homepage_uri: https://github.com/drbrain/net-http-persistent
66
- post_install_message:
67
85
  rdoc_options:
68
86
  - "--main"
69
87
  - README.rdoc
@@ -80,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
98
  - !ruby/object:Gem::Version
81
99
  version: '0'
82
100
  requirements: []
83
- rubygems_version: 3.0.3.1
84
- signing_key:
101
+ rubygems_version: 4.0.3
85
102
  specification_version: 4
86
103
  summary: Manages persistent connections using Net::HTTP including a thread pool for
87
104
  connecting to multiple hosts