lib/onstomp/connections/base.rb in onstomp-1.0.4 vs lib/onstomp/connections/base.rb in onstomp-1.0.5

- old
+ new

@@ -218,9 +218,16 @@ rescue Errno::EINTR, Errno::EAGAIN, Errno::EWOULDBLOCK # do not rescue EOFError triggered_close $!.message rescue Exception + # TODO: Fix this potential race condition the right way. + # This is the problematic area! If the user (or failover library) + # try to reconnect the Client when the connection is closed, the + # exception won't be raised until the IO Processing thread has + # already been joined to the main thread. Thus, the connection gets + # re-established, the "dying" thread re-enters here, and immediately + # raises the exception that terminated it. triggered_close $!.message, :terminated raise end elsif check_timeout && read_timeout_exceeded? triggered_close 'read blocked', :blocked