padrino-framework
padrino-framework copied to clipboard
Fix remove_constant to stop removing constants that are already remove_constanted but not GCed
I found a bug with remove_constant
and GC.
I wll later give an example that potentially causes this bug.
@genkami Could you provide an example for reproducing the error?
I added a test case that reproduces the errror. It fails without 8542c62.
This is how this error occurs:
- First, we require two files:
t.rb
,u.rb
-
t.rb
requiresv.rb
,w.rb
,x.rb
with nestedrequire_dependencies
. - The first loading of
v.rb
fails andV
is removed because it depends onw.rb
. (we call thisV
V1
) - Then,
w.rb
is loaded successfully, and it definesW
. - Then, we try to load
x.rb
, but it fails becausex.rb
depends ony.rb
- Then, we try to load
v.rb
again, and it succeeds. (we call theV
defined hereV2
) - Eventually, we find that we can't load
x.rb
because we can't resolve its dependencies. - After all, the entire process of loading
t.rb
is considered as failure. - All constants that are defined in loading
a.rb
are going to be rollbacked, except forV2
andW
. In this situation,V1
are considered as a constant that should be removed because it's defined in neitherv.rb
norw.rb
. So we tries to removeV1
, but it results to removingV2
becauseV1.to_s == V2.to_s == "V"
. - After rollback, we load
x.rb
and its dependency (y.rb
). - Then, we try to load
t.rb
again, but onlyx.rb
are loaded ast.rb
's dependencies, because we already loadedv.rb
with no rollback. - As a result,
V
is never defined.