lib/bunny/session.rb in bunny-0.9.5 vs lib/bunny/session.rb in bunny-0.9.6
- old
+ new
@@ -257,12 +257,17 @@
def close
if @transport.open?
close_all_channels
Bunny::Timer.timeout(@transport.disconnect_timeout, ClientTimeout) do
- self.close_connection(false)
+ self.close_connection(true)
end
+
+ maybe_shutdown_reader_loop
+ close_transport
+
+ @status = :closed
end
end
alias stop close
# Creates a temporary channel, yields it to the block given to this
@@ -397,15 +402,10 @@
@origin_thread.raise(@last_connection_error)
when AMQ::Protocol::Connection::CloseOk then
@last_connection_close_ok = method
begin
@continuations.clear
-
- reader_loop.stop
- @reader_loop = nil
-
- @transport.close
rescue StandardError => e
@logger.error e.class.name
@logger.error e.message
@logger.error e.backtrace
ensure
@@ -615,10 +615,30 @@
@reader_loop ||= ReaderLoop.new(@transport, self, Thread.current)
end
# @private
def maybe_shutdown_reader_loop
- @reader_loop.stop if @reader_loop
+ if @reader_loop
+ @reader_loop.stop
+ # We don't need to kill the loop but
+ # this is the easiest way to wait until the loop
+ # is guaranteed to have terminated
+ @reader_loop.kill
+ end
+
+ @reader_loop = nil
+ end
+
+ # @private
+ def close_transport
+ begin
+ @transport.close
+ rescue StandardError => e
+ @logger.error "Exception when closing transport:"
+ @logger.error e.class.name
+ @logger.error e.message
+ @logger.error e.backtrace
+ end
end
# @private
def signal_activity!
@heartbeat_sender.signal_activity! if @heartbeat_sender