bunny 2.3.0 → 2.3.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
  SHA1:
3
- metadata.gz: e10debc2fea6cb3ed014eeebdef45e41e7dad3b4
4
- data.tar.gz: 12d0bb9c3a0878b4831c2fe448fe09a0a0207c6d
3
+ metadata.gz: d0ff7b5af604687e3c750723a694563dbb26531b
4
+ data.tar.gz: 46b8f5c4414063ffa1732b76b60d62aa38f16e5d
5
5
  SHA512:
6
- metadata.gz: ac653c25bc8bd4b8da57e68e0f077f2466eb374da3427f24a9ce62d87cd980246d1785728cf55969d90806bee886390f4ec625732a65903722704d8faa0308f3
7
- data.tar.gz: b7d5b2b007e2f1a13240f44df4bcb302155f4d4333950d73ec38e492f3526e971fc2094963489c68af0f13664c906c00eb793dc195ded4d3f829ba7e4d0bd550
6
+ metadata.gz: e30fd008a99b0c0747c7b561d9026c04364a6eadb18f1eed34691aa49d3b504a251f210c58bd9251b3fc18ad8d10001b8a954c7c73d43ae068dd27f8ff03470a
7
+ data.tar.gz: 2147b893b63274e8c1d9f6a9e01f3bd02a84446d26d533912f2525a3b1bb51c1409c100cd973bb6e9c88676266924c9f08f5c9e241bf7f1d8d278963eca31720
data/ChangeLog.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## Changes between Bunny 2.3.0 and 2.3.1 (Apr 4th, 2016)
2
+
3
+ ### Support (Quoted) IPv6 Addresses in Address Lists
4
+
5
+ GitHub issue: [#383](https://github.com/ruby-amqp/bunny/issues/383).
6
+
7
+ Contributed by Jeremy Heiler.
8
+
9
+ ### Transport#read_fully Doesn't Try to Recover
10
+
11
+ Since transport is replaced by a recovering connection
12
+ anyway, and this produces confusing errors up the stack.
13
+
14
+ GitHub issue: [#359](https://github.com/ruby-amqp/bunny/issues/359)
15
+
16
+ Contributed by Donal McBreen.
17
+
18
+
19
+
1
20
  ## Changes between Bunny 2.2.0 and 2.3.0 (Feb 26th, 2016)
2
21
 
3
22
  ### Thread#abort_on_exception Setting for Consumer Work Pool Threads
data/lib/bunny/channel.rb CHANGED
@@ -1415,7 +1415,6 @@ module Bunny
1415
1415
  Bunny::Timeout.timeout(wait_on_continuations_timeout, ClientTimeout) do
1416
1416
  @last_confirm_select_ok = wait_on_continuations
1417
1417
  end
1418
- @confirm_mode = true
1419
1418
  raise_if_continuation_resulted_in_a_channel_error!
1420
1419
  @last_confirm_select_ok
1421
1420
  end
@@ -20,7 +20,7 @@ module Bunny
20
20
  attr_reader :channel
21
21
 
22
22
  # @private
23
- def initialize(get_ok, consumer, channel)
23
+ def initialize(get_ok, channel)
24
24
  @get_ok = get_ok
25
25
  @hash = {
26
26
  :delivery_tag => @get_ok.delivery_tag,
data/lib/bunny/queue.rb CHANGED
@@ -250,7 +250,7 @@ module Bunny
250
250
 
251
251
  if block
252
252
  if properties
253
- di = GetResponse.new(get_response, properties, @channel)
253
+ di = GetResponse.new(get_response, @channel)
254
254
  mp = MessageProperties.new(properties)
255
255
 
256
256
  block.call(di, mp, content)
@@ -259,7 +259,7 @@ module Bunny
259
259
  end
260
260
  else
261
261
  if properties
262
- di = GetResponse.new(get_response, properties, @channel)
262
+ di = GetResponse.new(get_response, @channel)
263
263
  mp = MessageProperties.new(properties)
264
264
  [di, mp, content]
265
265
  else
@@ -33,7 +33,7 @@ module Bunny
33
33
  begin
34
34
  break if @mutex.synchronize { @stopping || @stopped || @network_is_down }
35
35
  run_once
36
- rescue AMQ::Protocol::EmptyResponseError, IOError, SystemCallError => e
36
+ rescue AMQ::Protocol::EmptyResponseError, IOError, SystemCallError, Timeout::Error => e
37
37
  break if terminate? || @session.closing? || @session.closed?
38
38
 
39
39
  log_exception(e)
data/lib/bunny/session.rb CHANGED
@@ -138,18 +138,23 @@ module Bunny
138
138
  @default_hosts_shuffle_strategy = Proc.new { |hosts| hosts.shuffle }
139
139
 
140
140
  @opts = opts
141
+ log_file = opts[:log_file] || opts[:logfile] || STDOUT
142
+ log_level = opts[:log_level] || ENV["BUNNY_LOG_LEVEL"] || Logger::WARN
143
+ # we might need to log a warning about ill-formatted IPv6 address but
144
+ # progname includes hostname, so init like this first
145
+ @logger = opts.fetch(:logger, init_default_logger_without_progname(log_file, log_level))
146
+
141
147
  @addresses = self.addresses_from(opts)
142
148
  @address_index = 0
143
149
 
150
+ # re-init, see above
151
+ @logger = opts.fetch(:logger, init_default_logger(log_file, log_level))
152
+
144
153
  @user = self.username_from(opts)
145
154
  @pass = self.password_from(opts)
146
155
  @vhost = self.vhost_from(opts)
147
156
  @threaded = opts.fetch(:threaded, true)
148
157
 
149
- log_file = opts[:log_file] || opts[:logfile] || STDOUT
150
- log_level = opts[:log_level] || ENV["BUNNY_LOG_LEVEL"] || Logger::WARN
151
- @logger = opts.fetch(:logger, init_default_logger(log_file, log_level))
152
-
153
158
  validate_connection_options(opts)
154
159
 
155
160
  # should automatic recovery from network failures be used?
@@ -774,11 +779,6 @@ module Bunny
774
779
  shuffle_strategy.call addresses
775
780
  end
776
781
 
777
- # @private
778
- def host_with_port?(address)
779
- address.include? ':'
780
- end
781
-
782
782
  # @private
783
783
  def port_from(options)
784
784
  fallback = if options[:tls] || options[:ssl]
@@ -790,14 +790,61 @@ module Bunny
790
790
  options.fetch(:port, fallback)
791
791
  end
792
792
 
793
+ # @private
794
+ def host_with_port?(address)
795
+ # we need to handle cases such as [2001:db8:85a3:8d3:1319:8a2e:370:7348]:5671
796
+ last_colon = address.rindex(":")
797
+ last_closing_square_bracket = address.rindex("]")
798
+
799
+ if last_closing_square_bracket.nil?
800
+ address.include?(":")
801
+ else
802
+ last_closing_square_bracket < last_colon
803
+ end
804
+ end
805
+
793
806
  # @private
794
807
  def host_from_address(address)
795
- address.split(":")[0]
808
+ # we need to handle cases such as [2001:db8:85a3:8d3:1319:8a2e:370:7348]:5671
809
+ last_colon = address.rindex(":")
810
+ last_closing_square_bracket = address.rindex("]")
811
+
812
+ if last_closing_square_bracket.nil?
813
+ parts = address.split(":")
814
+ # this looks like an unquoted IPv6 address, so emit a warning
815
+ if parts.size > 2
816
+ @logger.warn "Address #{address} looks like an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]"
817
+ end
818
+ return parts[0]
819
+ end
820
+
821
+ if last_closing_square_bracket < last_colon
822
+ # there is a port
823
+ address[0, last_colon]
824
+ elsif last_closing_square_bracket > last_colon
825
+ address
826
+ end
796
827
  end
797
828
 
798
829
  # @private
799
830
  def port_from_address(address)
800
- address.split(":")[1].to_i
831
+ # we need to handle cases such as [2001:db8:85a3:8d3:1319:8a2e:370:7348]:5671
832
+ last_colon = address.rindex(":")
833
+ last_closing_square_bracket = address.rindex("]")
834
+
835
+ if last_closing_square_bracket.nil?
836
+ parts = address.split(":")
837
+ # this looks like an unquoted IPv6 address, so emit a warning
838
+ if parts.size > 2
839
+ @logger.warn "Address #{address} looks like an unquoted IPv6 address. Make sure you quote IPv6 addresses like so: [2001:db8:85a3:8d3:1319:8a2e:370:7348]"
840
+ end
841
+ return parts[1].to_i
842
+ end
843
+
844
+ if last_closing_square_bracket < last_colon
845
+ # there is a port
846
+ address[(last_colon + 1)..-1].to_i
847
+ end
801
848
  end
802
849
 
803
850
  # @private
@@ -1220,6 +1267,15 @@ module Bunny
1220
1267
  end
1221
1268
  end
1222
1269
 
1270
+ # @private
1271
+ def init_default_logger_without_progname(logfile, level)
1272
+ @default_logger = begin
1273
+ lgr = ::Logger.new(logfile)
1274
+ lgr.level = normalize_log_level(level)
1275
+ lgr
1276
+ end
1277
+ end
1278
+
1223
1279
  # @private
1224
1280
  def normalize_log_level(level)
1225
1281
  case level
@@ -218,7 +218,7 @@ module Bunny
218
218
  @status = :not_connected
219
219
 
220
220
  if @session.automatically_recover?
221
- @session.handle_network_failure(e)
221
+ raise
222
222
  else
223
223
  @session_thread.raise(Bunny::NetworkFailure.new("detected a network failure: #{e.message}", e))
224
224
  end
data/lib/bunny/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bunny
4
4
  # @return [String] Version of the library
5
- VERSION = "2.3.0"
5
+ VERSION = "2.3.1"
6
6
  end
@@ -192,6 +192,83 @@ describe Bunny::Session do
192
192
  end
193
193
  end
194
194
 
195
+ context "initialized with :addresses => [...] with quoted IPv6 hostnames" do
196
+ after :each do
197
+ subject.close if subject.open?
198
+ end
199
+
200
+ let(:host) { "[2001:db8:85a3:8d3:1319:8a2e:370:7348]" }
201
+ let(:port) { 5673 }
202
+ let(:address) { "#{host}:#{port}" }
203
+ let(:addresses) { [address] }
204
+ let(:subject) { described_class.new(:addresses => addresses) }
205
+
206
+ it "uses correct hostname" do
207
+ expect(subject.host).to eq host
208
+ expect(subject.hostname).to eq host
209
+ end
210
+
211
+ it "uses port 5673" do
212
+ expect(subject.port).to eq port
213
+ end
214
+
215
+ it "uses username = guest" do
216
+ expect(subject.username).to eq username
217
+ expect(subject.user).to eq username
218
+ end
219
+ end
220
+
221
+ context "initialized with :addresses => [...] with quoted IPv6 hostnames without ports" do
222
+ after :each do
223
+ subject.close if subject.open?
224
+ end
225
+
226
+ let(:host) { "[2001:db8:85a3:8d3:1319:8a2e:370:7348]" }
227
+ let(:address) { host }
228
+ let(:addresses) { [address] }
229
+ let(:subject) { described_class.new(:addresses => addresses) }
230
+
231
+ it "uses correct hostname" do
232
+ expect(subject.host).to eq host
233
+ expect(subject.hostname).to eq host
234
+ end
235
+
236
+ it "uses port 5672" do
237
+ expect(subject.port).to eq 5672
238
+ end
239
+
240
+ it "uses username = guest" do
241
+ expect(subject.username).to eq username
242
+ expect(subject.user).to eq username
243
+ end
244
+ end
245
+
246
+ context "initialized with :addresses => [...] with an quoted IPv6 hostnames" do
247
+ after :each do
248
+ subject.close if subject.open?
249
+ end
250
+
251
+ let(:host) { "2001:db8:85a3:8d3:1319:8a2e:370:7348" }
252
+ let(:port) { 5673 }
253
+ let(:address) { "#{host}:#{port}" }
254
+ let(:addresses) { [address] }
255
+ let(:subject) { described_class.new(:addresses => addresses) }
256
+
257
+ it "fails to correctly parse the host (and emits a warning)" do
258
+ expect(subject.host).to eq "2001"
259
+ expect(subject.hostname).to eq "2001"
260
+ end
261
+
262
+ it "fails to correctly parse the port (and emits a warning)" do
263
+ expect(subject.port).to eq 0
264
+ end
265
+
266
+ it "uses username = guest" do
267
+ expect(subject.username).to eq username
268
+ expect(subject.user).to eq username
269
+ end
270
+ end
271
+
195
272
  context "initialized with conflicting hosts and addresses" do
196
273
  let(:host) { "192.168.1.10" }
197
274
  let(:port) { 5673 }
@@ -259,9 +336,9 @@ describe Bunny::Session do
259
336
  :password => "bunny_password",
260
337
  :vhost => "bunny_testbed",
261
338
  :tls => true,
262
- :tls_cert => "spec/tls/client_cert.pem",
339
+ :tls_cert => "spec/tls/client_certificate.pem",
263
340
  :tls_key => "spec/tls/client_key.pem",
264
- :tls_ca_certificates => ["./spec/tls/cacert.pem"])
341
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"])
265
342
  end
266
343
 
267
344
  it "uses TLS port" do
@@ -52,7 +52,7 @@ describe Bunny::Session do
52
52
 
53
53
  describe "that recovers from connection.close" do
54
54
  it "can be closed" do
55
- c = Bunny.new(:automatically_recover => false, :recover_from_connection_close => true, :network_recovery_interval => 0.2)
55
+ c = Bunny.new(:automatically_recover => true, :recover_from_connection_close => true, :network_recovery_interval => 0.2)
56
56
  c.start
57
57
  ch = c.create_channel
58
58
 
@@ -37,9 +37,9 @@ unless ENV["CI"]
37
37
  :password => "bunny_password",
38
38
  :vhost => "bunny_testbed",
39
39
  :tls => true,
40
- :tls_cert => "spec/tls/client_cert.pem",
40
+ :tls_cert => "spec/tls/client_certificate.pem",
41
41
  :tls_key => "spec/tls/client_key.pem",
42
- :tls_ca_certificates => ["./spec/tls/cacert.pem"],
42
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"],
43
43
  :verify_peer => false)
44
44
  c.start
45
45
  c
@@ -59,7 +59,7 @@ unless ENV["CI"]
59
59
  :password => "bunny_password",
60
60
  :vhost => "bunny_testbed",
61
61
  :tls => true,
62
- :tls_ca_certificates => ["./spec/tls/cacert.pem"],
62
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"],
63
63
  :verify_peer => false)
64
64
  c.start
65
65
  c
@@ -76,9 +76,9 @@ unless ENV["CI"]
76
76
  describe "TLS connection to RabbitMQ with a connection string" do
77
77
  let(:connection) do
78
78
  c = Bunny.new("amqps://bunny_gem:bunny_password@127.0.0.1/bunny_testbed",
79
- :tls_cert => "spec/tls/client_cert.pem",
79
+ :tls_cert => "spec/tls/client_certificate.pem",
80
80
  :tls_key => "spec/tls/client_key.pem",
81
- :tls_ca_certificates => ["./spec/tls/cacert.pem"],
81
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"],
82
82
  :verify_peer => false)
83
83
  c.start
84
84
  c
@@ -95,7 +95,7 @@ unless ENV["CI"]
95
95
  describe "TLS connection to RabbitMQ with a connection string and w/o client certificate and key" do
96
96
  let(:connection) do
97
97
  c = Bunny.new("amqps://bunny_gem:bunny_password@127.0.0.1/bunny_testbed",
98
- :tls_ca_certificates => ["./spec/tls/cacert.pem"],
98
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"],
99
99
  :verify_peer => false)
100
100
  c.start
101
101
  c
@@ -115,9 +115,9 @@ unless ENV["CI"]
115
115
  :password => "bunny_password",
116
116
  :vhost => "bunny_testbed",
117
117
  :tls => true,
118
- :tls_cert => File.read("./spec/tls/client_cert.pem"),
118
+ :tls_cert => File.read("./spec/tls/client_certificate.pem"),
119
119
  :tls_key => File.read("./spec/tls/client_key.pem"),
120
- :tls_ca_certificates => ["./spec/tls/cacert.pem"],
120
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"],
121
121
  :verify_peer => false)
122
122
  c.start
123
123
  c
@@ -137,7 +137,7 @@ unless ENV["CI"]
137
137
  :vhost => "bunny_testbed",
138
138
  :tls => true,
139
139
  :tls_protocol => :TLSv1,
140
- :tls_ca_certificates => ["./spec/tls/cacert.pem"],
140
+ :tls_ca_certificates => ["./spec/tls/ca_certificate.pem"],
141
141
  :verify_peer => false)
142
142
  c.start
143
143
  c
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-26 00:00:00.000000000 Z
15
+ date: 2016-04-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: amq-protocol