lib/xmpp4r-simple.rb in xmpp4r-simple-0.8.7 vs lib/xmpp4r-simple.rb in xmpp4r-simple-0.8.8
- old
+ new
@@ -379,9 +379,13 @@
def connect!
raise ConnectionError, "Connections are disabled - use Jabber::Simple::force_connect() to reconnect." if @disconnected
# Pre-connect
@connect_mutex ||= Mutex.new
+
+ # don't try to connect if another thread is already connecting.
+ return if @connect_mutex.locked?
+
@connect_mutex.lock
disconnect!(false) if connected?
# Connect
jid = JID.new(@jid)