uv-rays 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cea80508dd174f1a92ad4b87d32920f23a85067a
4
- data.tar.gz: 6e2e6455a4b672a93fa9726df89ee71a1d2458b0
3
+ metadata.gz: f5e3a19099c48894d72cc8564ebc6ba7064f0e29
4
+ data.tar.gz: de7efbff60dcd1a46422a7f0ac5c6987c304f878
5
5
  SHA512:
6
- metadata.gz: ac4510a1e95d2547a82e5d8367c5ce47edeabb775065de0de5afedc545a0fc3b4d21539eff6311b91795f2d9e082dac01e36ff4f773615d1777b6f238ad2f636
7
- data.tar.gz: e21553e82432cb7b15db6ca134f026ec02c591ebd095ffe09fdee5f24c71dbc7f7111792bc3f52557cf90601ec1958a72a4fcaf0c14587539fbc65cae50190c3
6
+ metadata.gz: b18f154b1a634972ac6a44d0e9bd0469449a11ffceeb1ba8576b23135b24573917cec7e2f9b585816ca5f0a3241b9041f9cf5b4075e83cb2419b5ecf67c06464
7
+ data.tar.gz: ad62948fc3168d392e5e22cfa74da92689811947fcc632982b3706b34b44909cb6823f3a9fe6f00e73859b4cb643c9b9e6a4dd2e9e871e4d426089759fbe3cc5
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'yard' # yard documentation
8
8
  task :default => :limited_spec
9
9
  RSpec::Core::RakeTask.new(:limited_spec) do |t|
10
10
  # Exclude network tests
11
- t.rspec_opts = "--tag ~network"
11
+ t.rspec_opts = "--tag ~network --tag ~mri_only"
12
12
  end
13
13
  RSpec::Core::RakeTask.new(:spec)
14
14
 
@@ -20,27 +20,38 @@ module UV
20
20
 
21
21
 
22
22
  def cookies_hash
23
- @endpoint.cookiejar.get_hash(@uri)
23
+ @cookiejar.get_hash(@uri)
24
24
  end
25
25
 
26
26
  def set_cookie(value)
27
- @endpoint.cookiejar.set(@uri, value)
27
+ @cookiejar.set(@uri, value)
28
28
  end
29
29
 
30
30
 
31
31
  def initialize(endpoint, options)
32
32
  super(endpoint.thread, endpoint.thread.defer)
33
33
 
34
+ @path = options[:path]
35
+ @method = options[:method]
36
+
37
+ @host = endpoint.host
38
+ @port = endpoint.port
39
+ @cookiejar = endpoint.cookiejar
40
+ @middleware = endpoint.middleware
41
+ @uri = "#{endpoint.scheme}://#{encode_host(@host, @port)}#{@path}"
42
+ endpoint = nil
43
+
34
44
  @options = options
35
- @endpoint = endpoint
36
45
  @ntlm_creds = options[:ntlm]
37
46
  @digest_creds = options[:digest]
38
47
  @challenge_retries = 0
39
48
 
40
- @path = options[:path]
41
- @method = options[:method]
42
- @uri = "#{endpoint.scheme}://#{encode_host(endpoint.host, endpoint.port)}#{@path}"
43
-
49
+ # Don't hold references to vars we don't require anymore
50
+ self.finally {
51
+ @host = @port = nil
52
+ @cookiejar = nil
53
+ @middleware = nil
54
+ }
44
55
  @error = proc { |reason| reject(reason) }
45
56
  end
46
57
 
@@ -91,7 +102,7 @@ module UV
91
102
  head, body = build_request, @options[:body]
92
103
  @transport = transport
93
104
 
94
- @endpoint.middleware.each do |m|
105
+ @middleware.each do |m|
95
106
  begin
96
107
  head, body = m.request(self, head, body) if m.respond_to?(:request)
97
108
  rescue => e
@@ -132,7 +143,7 @@ module UV
132
143
  transport.write(request_header).catch @error
133
144
 
134
145
  # Send file
135
- fileRef = @endpoint.reactor.file file, File::RDONLY do
146
+ fileRef = @reactor.file file, File::RDONLY do
136
147
  # File is open and available for reading
137
148
  pSend = fileRef.send_file(transport, using: :raw, wait: :promise)
138
149
  pSend.catch @error
@@ -180,7 +191,7 @@ module UV
180
191
  head = @options[:headers] ? munge_header_keys(@options[:headers]) : {}
181
192
 
182
193
  # Set the cookie header if provided
183
- @cookies = @endpoint.cookiejar.get(@uri)
194
+ @cookies = @cookiejar.get(@uri)
184
195
  if cookie = head[COOKIE]
185
196
  @cookies << encode_cookie(cookie)
186
197
  end
@@ -192,7 +203,7 @@ module UV
192
203
  end
193
204
 
194
205
  # Set the Host header if it hasn't been specified already
195
- head['host'] ||= encode_host(@endpoint.host, @endpoint.port)
206
+ head['host'] ||= encode_host(@host, @port)
196
207
 
197
208
  # Set the User-Agent if it hasn't been specified
198
209
  if !head.key?('user-agent')
@@ -60,9 +60,11 @@ module UV
60
60
  end
61
61
 
62
62
  def on_close # user to define
63
- req = @request
63
+ @client.connection_closed(@request, @reason)
64
+ ensure
64
65
  @request = nil
65
- @client.connection_closed(req, @reason)
66
+ @client = nil
67
+ @reason = nil
66
68
  end
67
69
 
68
70
  def close_connection(request = nil)
@@ -91,11 +93,6 @@ module UV
91
93
  @options = @@defaults.merge(options)
92
94
  @tls_options = options[:tls_options] || {}
93
95
  @inactivity_timeout = options[:inactivity_timeout] || 10000
94
- @idle_timeout_method = method(:idle_timeout)
95
-
96
- if @inactivity_timeout > 0
97
- @timer = @thread.timer
98
- end
99
96
 
100
97
  uri = URI.parse host
101
98
  @port = uri.port
@@ -225,17 +222,17 @@ module UV
225
222
 
226
223
 
227
224
  def start_timer
228
- return if @timer.nil?
229
- @timer.progress @idle_timeout_method
230
- @timer.start @inactivity_timeout
231
- end
232
-
233
- def restart_timer
234
- @timer.again unless @timer.nil?
225
+ @timer.cancel if @timer
226
+ @timer = @thread.scheduler.in(@inactivity_timeout) do
227
+ @timer = nil
228
+ idle_timeout
229
+ end
235
230
  end
231
+ alias_method :restart_timer, :start_timer
236
232
 
237
233
  def stop_timer
238
- @timer.stop unless @timer.nil?
234
+ @timer.cancel unless @timer.nil?
235
+ @timer = nil
239
236
  end
240
237
 
241
238
  def idle_timeout
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UV
4
- VERSION = '2.1.2'
4
+ VERSION = '2.1.3'
5
5
  end
@@ -218,6 +218,52 @@ describe UV::HttpEndpoint do
218
218
  expect(@response.body).to eq('y')
219
219
  end
220
220
 
221
+ it 'should be garbage collected', mri_only: true do
222
+ require 'weakref'
223
+ require 'objspace'
224
+
225
+ objs = nil
226
+ obj_id = nil
227
+
228
+ @reactor.run { |reactor|
229
+ tcp = UV.start_server '127.0.0.1', 3250, HttpServer
230
+ block = proc {
231
+ server = UV::HttpEndpoint.new 'http://127.0.0.1:3250', inactivity_timeout: 300
232
+ obj_id = server.object_id
233
+ objs = WeakRef.new(server)
234
+
235
+ request = server.get(:path => '/whatwhat')
236
+ request.catch(@request_failure)
237
+ request.finally {
238
+ tcp.close
239
+ @timeout.stop
240
+ }
241
+
242
+ server = nil
243
+ request = nil
244
+ }
245
+
246
+ block.call
247
+
248
+ reactor.scheduler.in(800) do
249
+ GC.start
250
+ ObjectSpace.garbage_collect
251
+ end
252
+ }
253
+ ObjectSpace.garbage_collect
254
+ GC.start
255
+
256
+ expect(@general_failure).to eq([])
257
+
258
+ begin
259
+ expect(objs.weakref_alive?).to eq(nil)
260
+ rescue Exception => e
261
+ objs = ObjectSpace.each_object.select{ |o| ObjectSpace.reachable_objects_from(o).map(&:object_id).include?(obj_id) }
262
+ puts "Objects referencing HTTP class:\n#{objs.inspect}\n"
263
+ raise e
264
+ end
265
+ end
266
+
221
267
  it "should return the response when no length is given and the connection is closed" do
222
268
  # I've seen IoT devices do this (projector screen controllers etc)
223
269
  @reactor.run { |reactor|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uv-rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libuv
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  version: '0'
245
245
  requirements: []
246
246
  rubyforge_project:
247
- rubygems_version: 2.6.10
247
+ rubygems_version: 2.6.12
248
248
  signing_key:
249
249
  specification_version: 4
250
250
  summary: Abstractions for working with Libuv