# Require infinite loop

**URL:** <https://www.ruby-forum.com/t/require-infinite-loop/137565>\
**Category:** IronRuby\
**Created:** [May 14, 2008, 7:29am UTC](https://www.ruby-forum.com/t/require-infinite-loop/137565 "2008-05-14T07:29:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wayne\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5ac83/32.png) [@Wayne\_K](https://www.ruby-forum.com/u/Wayne_K)\
**Post date:** [May 14, 2008, 7:29am UTC](https://www.ruby-forum.com/t/require-infinite-loop/137565/1 "2008-05-14T07:29:06Z")

</div>

With the latest version, if a ruby source file requires itself, or if  
there is a cyclic chain of requires so that the original source file is  
required again - it results in an infinite loop.

This used to work correctly in the previous version - it simply requires  
marking the file as already loaded prior to executing it.

Cheers, Wayne.

---

<div class="post-metadata">

**Author:** ![Wayne\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5ac83/32.png) [@Wayne\_K](https://www.ruby-forum.com/u/Wayne_K)\
**Post date:** [May 14, 2008, 8:14am UTC](https://www.ruby-forum.com/t/require-infinite-loop/137565/2 "2008-05-14T08:14:23Z")

</div>

Well, it is not so simple. Currently we check whether the file is  
already in $". But it doesn’t get into the list until it’s execution is  
successfully finished:

x.rb:  
p $"  
require ‘y.rb’  
p $"

y.rb:  
p $"

The output is:  
[]  
[]  
[“y.rb”]

So we probably need another list/table of already loaded files. Besides,  
a single file could be required multiple times - if you do $".clear  
before calling require. I need to figure out what is exactly the  
condition under which Ruby doesn’t load a file. Could you please file a  
bug?

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Wayne K.  
Sent: Tuesday, May 13, 2008 10:23 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] require infinite loop

With the latest version, if a ruby source file requires itself, or if  
there is a cyclic chain of requires so that the original source file is  
required again - it results in an infinite loop.

This used to work correctly in the previous version - it simply requires  
marking the file as already loaded prior to executing it.

Cheers, Wayne.
