ethon 0.19.0 → 0.19.1

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: 273826aa45dfd8fa89c7d86117d443a2460d7f766b0e1a0a717b2dcbb2af0b17
4
- data.tar.gz: 2338c623556755ff816e49065fd15147084b0d6f3e14147de8cd6635c6229ba8
3
+ metadata.gz: 495f7cdb119483c6c3876354aa1ceeb8ae485ac25708280104213b2df28949e8
4
+ data.tar.gz: 6343bc21b68edfbce32389f739880c40a3506640249341c6bbd6eeca250e958f
5
5
  SHA512:
6
- metadata.gz: 315d41d82ee366321ae2c0908b4d71d0d828c2533e2091923e5024ea364eee45858eb9e6b3c8bc00695e9443f4af2ed4e4b1c2acb8b962ff525988b24e2e75b9
7
- data.tar.gz: f261db31635084b16314f58be9b2f525d89083a352db5ac96d88ed5e584f4e05c7d1cc116238186ccd656ca751989deee3d72900cec1f5e3c852ba57b65fe8ef
6
+ metadata.gz: e55248f897175f82a169ce09bb6a5b344f867027a3c3386935394adf058e0693501502ceb1cecb5748b1e1d7ca4c39eb0ce83321ee45ceb4ac73f5e0c032ba98
7
+ data.tar.gz: afbcbd73dc6a6e38f765d8ce89258711401b58cdda70e2b1fb7399d49b8bb0825fb400a47e489c4e23f86a222711859318550278056829fa7a87b2679e20505c
data/CHANGELOG.md CHANGED
@@ -2,7 +2,31 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.19.0...master)
5
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.19.1...master)
6
+
7
+ ## 0.19.1
8
+
9
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.19.0...v0.19.1)
10
+
11
+ ### Behavior changes
12
+
13
+ * Size a Multi's connection cache to twice the largest number of easy handles
14
+ attached at once. libcurl derives its default `CURLMOPT_MAXCONNECTS` from the
15
+ number of handles attached when a connection is returned, but Ethon detaches
16
+ finished handles immediately, which made the default shrink during a run and
17
+ close connections that later requests could have reused. An explicit
18
+ `maxconnects:` still takes precedence.
19
+ ([#455](https://github.com/typhoeus/ethon/pull/455))
20
+
21
+ ### Fixes and hardening
22
+
23
+ * Allow `Easy#cleanup` from an `on_complete` callback. The transfer has
24
+ finished and a Multi detaches the handle before its callbacks run, so freeing
25
+ it is safe. Cleanup from body, header, and progress callbacks is still
26
+ rejected. This fixes `:resolve` requests in Typhoeus 1.7.0, which clean up
27
+ instead of pooling to avoid leaking `CURLOPT_RESOLVE` entries.
28
+ ([#456](https://github.com/typhoeus/ethon/pull/456),
29
+ [typhoeus#824](https://github.com/typhoeus/typhoeus/issues/824))
6
30
 
7
31
  ## 0.19.0
8
32
 
@@ -103,12 +103,17 @@ module Ethon
103
103
  # Cleanup is terminal: the native handle is freed and the Easy cannot be
104
104
  # used again. Reusing it raises Ethon::Errors::EthonError.
105
105
  #
106
+ # Cleanup is allowed from an on_complete callback: the transfer has
107
+ # finished and a Multi detaches the handle before running its callbacks.
108
+ # Cleanup from body, header, and progress callbacks is rejected because
109
+ # those run inside libcurl.
110
+ #
106
111
  # @example Perform clean up.
107
112
  # easy.cleanup
108
113
  #
109
114
  # @return the result of the free which is nil
110
115
  def cleanup
111
- ensure_not_performing!
116
+ ensure_not_in_transfer!
112
117
  ensure_not_attached_to_multi!
113
118
 
114
119
  # Resolve the handle first: cleanup must not clear the response body if
@@ -32,6 +32,9 @@ module Ethon
32
32
 
33
33
  # Sets maxconnects option.
34
34
  #
35
+ # An explicit value also disables the automatic sizing described in
36
+ # #raise_default_maxconnects.
37
+ #
35
38
  # @example Set maxconnects option.
36
39
  # multi.maxconnects = $value
37
40
  #
@@ -39,7 +42,8 @@ module Ethon
39
42
  #
40
43
  # @return [ void ]
41
44
  def maxconnects=(value)
42
- Curl.set_option(:maxconnects, value_for(value, :int, :maxconnects), handle, :multi)
45
+ @maxconnects_configured = true unless value.nil?
46
+ set_maxconnects(value)
43
47
  end
44
48
 
45
49
  # Sets max_host_connections option.
@@ -156,6 +160,30 @@ module Ethon
156
160
 
157
161
  private
158
162
 
163
+ # Raise the default connection cache size to twice the largest number
164
+ # of easy handles ever attached at once.
165
+ #
166
+ # libcurl derives its default from the number of handles attached when
167
+ # a connection is returned. Ethon detaches each handle as soon as its
168
+ # transfer finishes, so that number falls during a run and libcurl
169
+ # closes connections that later requests could have reused.
170
+ #
171
+ # @param [ Integer ] count The number of attached handles after the
172
+ # pending add.
173
+ #
174
+ # @return [ void ]
175
+ def raise_default_maxconnects(count)
176
+ return if @maxconnects_configured
177
+ return if count <= (@maxconnects_high_water ||= 0)
178
+
179
+ @maxconnects_high_water = count
180
+ set_maxconnects(2 * count)
181
+ end
182
+
183
+ def set_maxconnects(value)
184
+ Curl.set_option(:maxconnects, value_for(value, :int, :maxconnects), handle, :multi)
185
+ end
186
+
159
187
  def retain_callback(option, callback)
160
188
  if callback.nil?
161
189
  @procs.delete(option) if @procs
@@ -48,6 +48,12 @@ module Ethon
48
48
  multi_handle = handle
49
49
  easy_handle = easy.handle
50
50
 
51
+ # Pin libcurl's default connection cache size before the handle is
52
+ # attached. Finished handles are detached immediately, which would
53
+ # otherwise make the default shrink during a run and close reusable
54
+ # connections.
55
+ raise_default_maxconnects(stack.size + 1)
56
+
51
57
  stack << easy
52
58
  begin
53
59
  code = Curl.multi_add_handle(multi_handle, easy_handle)
data/lib/ethon/multi.rb CHANGED
@@ -55,9 +55,13 @@ module Ethon
55
55
  # as the Multi may invoke the callback. (Added in 7.16.0)
56
56
  # @option options :maxconnects [Integer]
57
57
  # Pass a long. The set number will be used as the maximum amount of
58
- # simultaneously open connections that libcurl may cache. Default is
59
- # 10, and libcurl will enlarge the size for each added easy handle to
60
- # make it fit 4 times the number of added easy handles.
58
+ # simultaneously open connections that libcurl may cache. When this is
59
+ # not set, Ethon sizes the cache to twice the largest number of easy
60
+ # handles attached to this Multi at once. libcurl derives its own default
61
+ # from the handles attached when a connection is returned, but Ethon
62
+ # detaches finished handles, which would otherwise shrink the cache during
63
+ # a run. Pass an explicit value to cap the cache yourself, or 0 to use
64
+ # libcurl's dynamic default.
61
65
  # By setting this option, you can prevent the cache size from growing
62
66
  # beyond the limit set by you.
63
67
  # When the cache is full, curl closes the oldest one in the cache to
data/lib/ethon/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  module Ethon
3
3
 
4
4
  # Ethon version.
5
- VERSION = '0.19.0'
5
+ VERSION = '0.19.1'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hans Hasselberg
@@ -134,10 +134,10 @@ licenses:
134
134
  - MIT
135
135
  metadata:
136
136
  bug_tracker_uri: https://github.com/typhoeus/ethon/issues
137
- changelog_uri: https://github.com/typhoeus/ethon/blob/v0.19.0/CHANGELOG.md
138
- documentation_uri: https://www.rubydoc.info/gems/ethon/0.19.0
137
+ changelog_uri: https://github.com/typhoeus/ethon/blob/v0.19.1/CHANGELOG.md
138
+ documentation_uri: https://www.rubydoc.info/gems/ethon/0.19.1
139
139
  rubygems_mfa_required: 'true'
140
- source_code_uri: https://github.com/typhoeus/ethon/tree/v0.19.0
140
+ source_code_uri: https://github.com/typhoeus/ethon/tree/v0.19.1
141
141
  post_install_message:
142
142
  rdoc_options: []
143
143
  require_paths: