restify 1.4.3 → 1.4.4

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
  SHA256:
3
- metadata.gz: 218f1484655662a863e6d65ae81f8f1cfe5e3127f9c795748b150236fe137225
4
- data.tar.gz: 440710396a4f3879ad78766ef074edc85a51c5e40b7b8a3ac685e41b5060abf3
3
+ metadata.gz: 05b4120c9755cdd5a88f172e3d5964eff3804add46785bd3cbec8b842f2af459
4
+ data.tar.gz: 5cb09e31e263560b373b156cfaa601925b9bde328ff892d4533c2738b10dff67
5
5
  SHA512:
6
- metadata.gz: 1d065b2b0b1080d937e311dcc7f820c41fad880262112887d57e5051888a069244809b3dd3e14307ce553277c82b8d56f602f5b891178f3df78b82aa45c13655
7
- data.tar.gz: a4fd01db3ece23055dc2b3d4c297f5caf06bb93294cc4e9cd79a72fcca87340014d5f03b90603be32a2dff8006df6fb3a6375056258cae2e669643dca4024ef1
6
+ metadata.gz: a5854443d09b5d6ce73f3a68da7c76e2ed7453288b4e9ef940cfb2e437b8666f0c4f03b6602405193728751b5ee2cf46a12937196d412e3d911d7b497e947daf
7
+ data.tar.gz: 535598e592a526d20cb8c5d93fe4926deea1d1f92f60bf5fd003115a56841462ad6ce475d96927a09b940524c622e80730ff06c858940c2d08e4ed8396fa8359
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.4
4
+
5
+ * Fix race condition in typhoeus adapter
6
+ * Add `#request` to `NetworkError` to ease debugging
7
+
3
8
  ## 1.4.3
4
9
 
5
10
  * Add advanced logging capabilities using logging gem
@@ -18,6 +18,7 @@ module Restify
18
18
  @sync = sync
19
19
  @hydra = ::Typhoeus::Hydra.new(**options)
20
20
  @mutex = Mutex.new
21
+ @signal = ConditionVariable.new
21
22
  end
22
23
 
23
24
  def sync?
@@ -29,21 +30,28 @@ module Restify
29
30
  logger.debug { "[#{request.object_id}] Queue request #{request}" }
30
31
  @hydra.queue convert(request, writer)
31
32
  @hydra.dequeue_many
32
- end
33
33
 
34
- sync? ? @hydra.run : thread.run
34
+ if sync?
35
+ @hydra.run
36
+ else
37
+ thread.run
38
+ @signal.signal
39
+ end
40
+ end
35
41
  end
36
42
 
37
43
  def queued?
38
- @mutex.synchronize do
39
- @hydra.queued_requests.any? || @hydra.multi.easy_handles.count > 0
40
- end
44
+ @mutex.synchronize { ns_queued? }
41
45
  end
42
46
 
43
47
  private
44
48
 
49
+ def ns_queued?
50
+ @hydra.queued_requests.any? || @hydra.multi.easy_handles.count > 0
51
+ end
52
+
45
53
  def convert(request, writer)
46
- req = ::Typhoeus::Request.new \
54
+ ::Typhoeus::Request.new(
47
55
  request.uri,
48
56
  method: request.method,
49
57
  headers: DEFAULT_HEADERS.merge(request.headers),
@@ -51,20 +59,19 @@ module Restify
51
59
  followlocation: true,
52
60
  timeout: request.timeout,
53
61
  connecttimeout: request.timeout
54
-
55
- req.on_complete do |response|
56
- logger.debug { "[#{request.object_id}] Completed: #{response.code}" }
57
-
58
- if response.timed_out?
59
- writer.reject Restify::Timeout.new request
60
- elsif response.code == 0
61
- writer.reject Restify::NetworkError.new response.return_message
62
- else
63
- writer.fulfill convert_back(response, request)
62
+ ).tap do |req|
63
+ req.on_complete do |response|
64
+ logger.debug { "[#{request.object_id}] Completed: #{response.code}" }
65
+
66
+ if response.timed_out?
67
+ writer.reject Restify::Timeout.new request
68
+ elsif response.code == 0
69
+ writer.reject Restify::NetworkError.new request, response.return_message
70
+ else
71
+ writer.fulfill convert_back(response, request)
72
+ end
64
73
  end
65
74
  end
66
-
67
- req
68
75
  end
69
76
 
70
77
  def convert_back(response, request)
@@ -103,8 +110,11 @@ module Restify
103
110
  @hydra.run
104
111
  logger.debug { 'Hydra finished' }
105
112
  else
106
- logger.debug { 'Pause hydra thread' }
107
- Thread.stop
113
+ @mutex.synchronize do
114
+ return if ns_queued?
115
+ logger.debug { 'Pause hydra thread' }
116
+ @signal.wait(@mutex)
117
+ end
108
118
  end
109
119
  rescue StandardError => e
110
120
  logger.error(e)
@@ -19,6 +19,12 @@ module Restify
19
19
  # unresolvable hosts or disconnects.
20
20
  #
21
21
  class NetworkError < StandardError
22
+ attr_reader :request
23
+
24
+ def initialize(request, message)
25
+ @request = request
26
+ super("[#{request.uri}] #{message}")
27
+ end
22
28
  end
23
29
 
24
30
  # A {ResponseError} is returned on a non-successful
@@ -4,7 +4,7 @@ module Restify
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 4
7
- PATCH = 3
7
+ PATCH = 4
8
8
  STAGE = nil
9
9
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  version: '0'
186
186
  requirements: []
187
187
  rubyforge_project:
188
- rubygems_version: 2.7.2
188
+ rubygems_version: 2.7.7
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: An experimental hypermedia REST client.