async-http 0.23.1 → 0.23.2

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: 7207e1954ae1668e09deb15b8f64218c74ff6f9ee6cb4fae89b80b3049f54201
4
- data.tar.gz: 4bf817e6c1c04458e37edea51c867bea9e69a0571868d9e49ea0d124202b7a1f
3
+ metadata.gz: 57206755197e6bd15038e9036eb5c6ab74a8942b6b00dae74d15eb999c7bf760
4
+ data.tar.gz: a59c0f71558d7b1ee34b21485cebda98bd30aef71744e83efd1c321b37622389
5
5
  SHA512:
6
- metadata.gz: 1337adfccba971eef65e3c66f189ec5037b0a9bc5b7f422008641863e8484ca65ced7ece6ac6e25b0bbef17d6c1b57e9d9306acf0b2151ec26cdafcd38219b82
7
- data.tar.gz: 1ade6934603866b12d10b99bc923c6659a30210c70dff74a744d43305eeb9369606b31008cb4bd5324505277ba10660f2bf697a8fb316efc2079d1e3e5c737a0
6
+ metadata.gz: 4d5e76a534e11c8045540c691882d0c92014bbb208444bfd1dbf265867da06deb324c89d5e04bb5fc28f3e71415d9a821797ac6b3614e6ef4b8b48c9ae115754
7
+ data.tar.gz: deea701332633244e625b516429ace7ac8892a86945facf3295aa6e81d4503de8db1136253f1cba3214cb4b5ff92b7ed47bf8318a4be5227fc977f25a02fc181
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency("async", "~> 1.6")
20
- spec.add_dependency("async-io", "~> 1.10")
20
+ spec.add_dependency("async-io", "~> 1.11")
21
21
 
22
22
  spec.add_dependency("http-2", "~> 0.9.0")
23
23
  # spec.add_dependency("openssl")
@@ -63,10 +63,11 @@ module Async
63
63
  request.authority ||= @authority
64
64
  attempt = 0
65
65
 
66
+ # There is a challenge with how this works. If you have 8 connections in the connection pool and they've all expired, retrying 3 times isn't going to work. We need to, perhaps, on the last retry, initiate a completely new connection.
66
67
  begin
67
68
  attempt += 1
68
69
 
69
- # As we cache connections, it's possible these connections go bad (e.g. closed by remote host). In this case, we need to try again. It's up to the caller to impose a timeout on this.
70
+ # As we cache connections, it's possible these connections go bad (e.g. closed by remote host). In this case, we need to try again. It's up to the caller to impose a timeout on this. If this is the last attempt, we force a new connection.
70
71
  connection = @connections.acquire
71
72
 
72
73
  response = connection.call(request)
@@ -58,17 +58,11 @@ module Async
58
58
 
59
59
  # Make the resource available and let waiting tasks know that there is something available.
60
60
  def release(resource)
61
+ # A resource that is not good should also not be reusable.
61
62
  if resource.reusable?
62
- Async.logger.debug(self) {"Reusing resource #{resource}"}
63
-
64
- @available[resource] -= 1
65
-
66
- if task = @waiting.pop
67
- task.resume
68
- end
63
+ reuse(resource)
69
64
  else
70
- Async.logger.debug(self) {"Closing resource: #{resource}"}
71
- resource.close
65
+ retire(resource)
72
66
  end
73
67
  end
74
68
 
@@ -79,6 +73,24 @@ module Async
79
73
 
80
74
  protected
81
75
 
76
+ def reuse(resource)
77
+ Async.logger.debug(self) {"Reuse #{resource}"}
78
+
79
+ @available[resource] -= 1
80
+
81
+ if task = @waiting.pop
82
+ task.resume
83
+ end
84
+ end
85
+
86
+ def retire(resource)
87
+ Async.logger.debug(self) {"Retire #{resource}"}
88
+
89
+ @available.delete(resource)
90
+
91
+ resource.close
92
+ end
93
+
82
94
  def wait_for_next_available
83
95
  until resource = next_available
84
96
  @waiting << Fiber.current
@@ -88,11 +100,11 @@ module Async
88
100
  return resource
89
101
  end
90
102
 
91
- def create_resource
103
+ def create
92
104
  begin
93
105
  # This might fail, which is okay :)
94
106
  resource = @constructor.call
95
- rescue StandardError
107
+ rescue
96
108
  Async.logger.error "#{$!}: #{$!.backtrace}"
97
109
  return nil
98
110
  end
@@ -102,19 +114,24 @@ module Async
102
114
  return resource
103
115
  end
104
116
 
105
- # TODO this does not take into account resources that start off good but can fail.
106
117
  def next_available
107
118
  @available.each do |resource, count|
108
119
  if count < resource.multiplex
109
- @available[resource] += 1
110
-
111
- return resource
120
+ # We want to use this resource... but is it good?
121
+ if resource.good?
122
+ @available[resource] += 1
123
+
124
+ return resource
125
+ else
126
+ retire(resource)
127
+ end
112
128
  end
113
129
  end
114
130
 
115
131
  if !@limit or @available.count < @limit
116
132
  Async.logger.debug(self) {"No available resources, allocating new one..."}
117
- return create_resource
133
+
134
+ return create
118
135
  end
119
136
  end
120
137
  end
@@ -55,6 +55,11 @@ module Async
55
55
  1
56
56
  end
57
57
 
58
+ # Can we use this connection to make requests?
59
+ def good?
60
+ @stream.connected?
61
+ end
62
+
58
63
  def reusable?
59
64
  @persistent && !@stream.closed?
60
65
  end
@@ -70,7 +70,7 @@ module Async
70
70
  Async.logger.error(self) {"goaway: #{payload.inspect}"}
71
71
 
72
72
  @reader.stop
73
- @stream.io.close
73
+ @stream.close
74
74
  end
75
75
 
76
76
  @count = 0
@@ -83,6 +83,11 @@ module Async
83
83
  @controller.remote_settings[:settings_max_concurrent_streams]
84
84
  end
85
85
 
86
+ # Can we use this connection to make requests?
87
+ def good?
88
+ @stream.connected?
89
+ end
90
+
86
91
  def reusable?
87
92
  !@stream.closed?
88
93
  end
@@ -149,6 +154,8 @@ module Async
149
154
  end
150
155
 
151
156
  stream.on(:half_close) do
157
+ # The requirements for this to be in lock-step with other opertaions is minimal.
158
+ # TODO consider putting this in it's own async task.
152
159
  begin
153
160
  # We are no longer receiving any more data frames:
154
161
  body.finish
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.23.1"
23
+ VERSION = "0.23.2"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.1
4
+ version: 0.23.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '1.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: http-2
43
43
  requirement: !ruby/object:Gem::Requirement