bunny 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## Changes between Bunny 0.9.5 and 0.9.6
2
+
3
+ ### Eliminated Race Condition in Bunny::Session#close
4
+
5
+ `Bunny::Session#close` had a race condition that caused (non-deterministic)
6
+ exceptions when connection transport was closed before connection
7
+ reader loop was guaranteed to have stopped.
8
+
9
+
1
10
  ## Changes between Bunny 0.9.4 and 0.9.5
2
11
 
3
12
  ### connection.close Raises Exceptions on Connection Thread
@@ -51,6 +51,8 @@ module Bunny
51
51
  @session_thread.raise(Bunny::NetworkFailure.new("caught an unexpected exception in the network loop: #{e.message}", e))
52
52
  end
53
53
  end
54
+
55
+ @stopped = true
54
56
  end
55
57
 
56
58
  def run_once
@@ -80,6 +82,10 @@ module Bunny
80
82
  @stopping = true
81
83
  end
82
84
 
85
+ def stopped?
86
+ @stopped = true
87
+ end
88
+
83
89
  def kill
84
90
  @thread.kill
85
91
  @thread.join
data/lib/bunny/session.rb CHANGED
@@ -259,8 +259,13 @@ module Bunny
259
259
  close_all_channels
260
260
 
261
261
  Bunny::Timer.timeout(@transport.disconnect_timeout, ClientTimeout) do
262
- self.close_connection(false)
262
+ self.close_connection(true)
263
263
  end
264
+
265
+ maybe_shutdown_reader_loop
266
+ close_transport
267
+
268
+ @status = :closed
264
269
  end
265
270
  end
266
271
  alias stop close
@@ -399,11 +404,6 @@ module Bunny
399
404
  @last_connection_close_ok = method
400
405
  begin
401
406
  @continuations.clear
402
-
403
- reader_loop.stop
404
- @reader_loop = nil
405
-
406
- @transport.close
407
407
  rescue StandardError => e
408
408
  @logger.error e.class.name
409
409
  @logger.error e.message
@@ -617,7 +617,27 @@ module Bunny
617
617
 
618
618
  # @private
619
619
  def maybe_shutdown_reader_loop
620
- @reader_loop.stop if @reader_loop
620
+ if @reader_loop
621
+ @reader_loop.stop
622
+ # We don't need to kill the loop but
623
+ # this is the easiest way to wait until the loop
624
+ # is guaranteed to have terminated
625
+ @reader_loop.kill
626
+ end
627
+
628
+ @reader_loop = nil
629
+ end
630
+
631
+ # @private
632
+ def close_transport
633
+ begin
634
+ @transport.close
635
+ rescue StandardError => e
636
+ @logger.error "Exception when closing transport:"
637
+ @logger.error e.class.name
638
+ @logger.error e.message
639
+ @logger.error e.backtrace
640
+ end
621
641
  end
622
642
 
623
643
  # @private
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 = "0.9.5"
5
+ VERSION = "0.9.6"
6
6
  end
@@ -1,12 +1,15 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Bunny::Session do
4
- it "can be closed" do
5
- c = Bunny.new
6
- c.start
7
- ch = c.create_channel
4
+ 4000.times do |i|
5
+ it "can be closed (take #{i})" do
6
+ c = Bunny.new(:automatically_recover => false)
7
+ c.start
8
+ ch = c.create_channel
8
9
 
9
- c.should be_connected
10
- c.stop
10
+ c.should be_connected
11
+ c.stop
12
+ c.should be_closed
13
+ end
11
14
  end
12
15
  end
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: 0.9.5
4
+ version: 0.9.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: