net-http-persistent 4.0.5 → 4.0.6
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 +4 -4
- data/History.txt +6 -0
- data/README.rdoc +1 -1
- data/lib/net/http/persistent/timed_stack_multi.rb +2 -1
- data/lib/net/http/persistent.rb +53 -40
- data/test/test_net_http_persistent.rb +21 -0
- data/test/test_net_http_persistent_timed_stack_multi.rb +19 -2
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85a943098d06763f4de093bc75563f2df1bb927471fadf3dd3b2c8bd9df22d36
|
4
|
+
data.tar.gz: 49b04bd17537e5d4939c987b64ac40e1747ee22fa9d5a98751962810bf279153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa114cb93989e4bd4d025b6c3823856efe39d0f06206d6f34605125d780306b7e22fc0c97e9a18737f9fe6d68acc73c23ab125a7f80ee68d90a93aa305dafbc
|
7
|
+
data.tar.gz: 492748215d7b48f67c6221728fb566297831cfc75715f97cc55dd8ac329b1082a1bac9163657961bb7fa8baef0ff407c74b1ff4a2c8f0286dcfe030109944549
|
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -63,7 +63,8 @@ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nod
|
|
63
63
|
if @created >= @max && @enqueued >= 1
|
64
64
|
oldest, = @lru.first
|
65
65
|
@lru.delete oldest
|
66
|
-
@ques[oldest].pop
|
66
|
+
connection = @ques[oldest].pop
|
67
|
+
connection.close if connection.respond_to?(:close)
|
67
68
|
|
68
69
|
@created -= 1
|
69
70
|
end
|
data/lib/net/http/persistent.rb
CHANGED
@@ -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
|
51
|
-
#
|
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.
|
184
|
+
VERSION = '4.0.6'
|
186
185
|
|
187
186
|
##
|
188
187
|
# Error class for errors raised by Net::HTTP::Persistent. Various
|
@@ -631,47 +630,49 @@ class Net::HTTP::Persistent
|
|
631
630
|
|
632
631
|
connection = @pool.checkout net_http_args
|
633
632
|
|
634
|
-
|
633
|
+
begin
|
634
|
+
http = connection.http
|
635
635
|
|
636
|
-
|
637
|
-
|
636
|
+
connection.ressl @ssl_generation if
|
637
|
+
connection.ssl_generation != @ssl_generation
|
638
638
|
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
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
|
645
645
|
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
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=)
|
651
|
+
|
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
|
651
661
|
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
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
|
670
|
+
end
|
661
671
|
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
address = http.proxy_address
|
666
|
-
port = http.proxy_port
|
667
|
-
else
|
668
|
-
address = http.address
|
669
|
-
port = http.port
|
672
|
+
raise Error, "host down: #{address}:#{port}"
|
673
|
+
ensure
|
674
|
+
@pool.checkin net_http_args
|
670
675
|
end
|
671
|
-
|
672
|
-
raise Error, "host down: #{address}:#{port}"
|
673
|
-
ensure
|
674
|
-
@pool.checkin net_http_args
|
675
676
|
end
|
676
677
|
|
677
678
|
##
|
@@ -996,7 +997,8 @@ class Net::HTTP::Persistent
|
|
996
997
|
end
|
997
998
|
|
998
999
|
##
|
999
|
-
# Shuts down all connections
|
1000
|
+
# Shuts down all connections. Attempting to checkout a connection after
|
1001
|
+
# shutdown will raise an error.
|
1000
1002
|
#
|
1001
1003
|
# *NOTE*: Calling shutdown for can be dangerous!
|
1002
1004
|
#
|
@@ -1007,6 +1009,17 @@ class Net::HTTP::Persistent
|
|
1007
1009
|
@pool.shutdown { |http| http.finish }
|
1008
1010
|
end
|
1009
1011
|
|
1012
|
+
##
|
1013
|
+
# Discard all existing connections. Subsequent checkouts will create
|
1014
|
+
# new connections as needed.
|
1015
|
+
#
|
1016
|
+
# If any thread is still using a connection it may cause an error! Call
|
1017
|
+
# #reload when you are completely done making requests!
|
1018
|
+
|
1019
|
+
def reload
|
1020
|
+
@pool.reload { |http| http.finish }
|
1021
|
+
end
|
1022
|
+
|
1010
1023
|
##
|
1011
1024
|
# Enables SSL on +connection+
|
1012
1025
|
|
@@ -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
|
@@ -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
|
|
@@ -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
|
|
@@ -57,7 +62,7 @@ class TestNetHttpPersistentTimedStackMulti < Minitest::Test
|
|
57
62
|
@stack.pop timeout: 0
|
58
63
|
end
|
59
64
|
|
60
|
-
|
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
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http-persistent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-05-29 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: connection_pool
|
@@ -17,6 +16,9 @@ dependencies:
|
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '2.2'
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.2.4
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +26,9 @@ dependencies:
|
|
24
26
|
- - "~>"
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: '2.2'
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.2.4
|
27
32
|
description: |-
|
28
33
|
Manages persistent connections using Net::HTTP including a thread pool for
|
29
34
|
connecting to multiple hosts.
|
@@ -63,7 +68,6 @@ licenses:
|
|
63
68
|
- MIT
|
64
69
|
metadata:
|
65
70
|
homepage_uri: https://github.com/drbrain/net-http-persistent
|
66
|
-
post_install_message:
|
67
71
|
rdoc_options:
|
68
72
|
- "--main"
|
69
73
|
- README.rdoc
|
@@ -80,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
84
|
- !ruby/object:Gem::Version
|
81
85
|
version: '0'
|
82
86
|
requirements: []
|
83
|
-
rubygems_version: 3.0.
|
84
|
-
signing_key:
|
87
|
+
rubygems_version: 3.6.0.dev
|
85
88
|
specification_version: 4
|
86
89
|
summary: Manages persistent connections using Net::HTTP including a thread pool for
|
87
90
|
connecting to multiple hosts
|