lib/bunny/session.rb in bunny-0.10.1 vs lib/bunny/session.rb in bunny-0.10.2
- old
+ new
@@ -224,11 +224,11 @@
self.init_connection
self.open_connection
@reader_loop = nil
- self.start_reader_loop if @threaded
+ self.start_reader_loop if threaded?
@default_channel = self.create_channel
rescue Exception => e
@status = :not_connected
raise e
@@ -267,13 +267,11 @@
Bunny::Timer.timeout(@transport.disconnect_timeout, ClientTimeout) do
self.close_connection(true)
end
- # puts "before maybe_shutdown_reader_loop"
maybe_shutdown_reader_loop
- # puts "after maybe_shutdown_reader_loop"
close_transport
@status = :closed
end
end
@@ -626,21 +624,25 @@
# @private
def maybe_shutdown_reader_loop
if @reader_loop
@reader_loop.stop
- # this is the easiest way to wait until the loop
- # is guaranteed to have terminated
- @reader_loop.raise(ShutdownSignal)
- # joining the thread here may take forever
- # on JRuby because sun.nio.ch.KQueueArrayWrapper#kevent0 is
- # a native method that cannot be (easily) interrupted.
- # So we use this ugly hack or else our test suite takes forever
- # to run on JRuby (a new connection is opened/closed per example). MK.
- if RUBY_ENGINE == "jruby"
- sleep 0.075
+ if threaded?
+ # this is the easiest way to wait until the loop
+ # is guaranteed to have terminated
+ @reader_loop.raise(ShutdownSignal)
+ # joining the thread here may take forever
+ # on JRuby because sun.nio.ch.KQueueArrayWrapper#kevent0 is
+ # a native method that cannot be (easily) interrupted.
+ # So we use this ugly hack or else our test suite takes forever
+ # to run on JRuby (a new connection is opened/closed per example). MK.
+ if RUBY_ENGINE == "jruby"
+ sleep 0.075
+ else
+ @reader_loop.join
+ end
else
- @reader_loop.join
+ # single threaded mode, nothing to do. MK.
end
end
@reader_loop = nil
end