By reading the code, I feel it's sort of unlikely that you'll actually hit an infinite loop, but it probably wouldn't be a bad idea either to wrap around the ```loop do``` block with a Timeout. Just in case?

Code example:

```ruby
require 'Timeout'

begin
	Timeout.timeout(3) do |i|
		loop do
			# Run this code for 3 seconds max
		end
	end
rescue Timeout::Error
	# Weird. That code has been running way to long. Bail.
end
```