You should add a return :abort if res.nil? before continue to avoid res being nil for example due to a timeout.