New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeakRef::RefError: Invalid Reference - probably recycled #863

Closed
GregOnNet opened this Issue Jun 8, 2016 · 7 comments

Comments

Projects
None yet
3 participants
@GregOnNet

GregOnNet commented Jun 8, 2016

Hi,

first thanks for the great and consistent work on nanoc.
Me and my team really appreciate it.

Problem

I create the used items inside a preprocess rule.
After upgrading to Nanoc 4.2.0 I experience the following error when I access @item inside a template:

Message:

WeakRef::RefError: Invalid Reference - probably recycled

Compilation stack:

  (empty)

Environment

Nanoc 4.2.0 © 2007-2016 Denis Defreyne.
Running ruby 2.2.4 (2015-12-16) on x64-mingw32 with RubyGems 2.4.5.1.

crash.log
crash.txt

Let me know if I can provide further information to this topic

Kind Regards
Gregor

@agross

This comment has been minimized.

Show comment
Hide comment
@agross

agross Jun 8, 2016

Contributor

Here's another stack trace with less haml and more nanoc:

crash.log.txt

Contributor

agross commented Jun 8, 2016

Here's another stack trace with less haml and more nanoc:

crash.log.txt

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Jun 8, 2016

Member

Yup, I am getting this one as well. This is caused by the recent change of #846, though I am not quite sure why.

Member

ddfreyne commented Jun 8, 2016

Yup, I am getting this one as well. This is caused by the recent change of #846, though I am not quite sure why.

@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Jun 8, 2016

Member

Potential fix in #865.

Member

ddfreyne commented Jun 8, 2016

Potential fix in #865.

@ddfreyne ddfreyne added this to the 4.2.1 milestone Jun 8, 2016

@agross

This comment has been minimized.

Show comment
Hide comment
@agross

agross Jun 8, 2016

Contributor

The only reason for this to fail seems be that GC occurs between the check for weakref_alive? and the actual retrieval of the value.

Contributor

agross commented Jun 8, 2016

The only reason for this to fail seems be that GC occurs between the check for weakref_alive? and the actual retrieval of the value.

@agross

This comment has been minimized.

Show comment
Hide comment
@agross

agross Jun 8, 2016

Contributor

Probably it's best to disable GC during check and retrieval?

Contributor

agross commented Jun 8, 2016

Probably it's best to disable GC during check and retrieval?

@agross

This comment has been minimized.

Show comment
Hide comment
@agross

agross Jun 8, 2016

Contributor

Yes, it seems GC is the culprit.

I added this:

+       require 'pry-byebug'
+       prestat = GC.stat
        if method_cache.key?(args) && method_cache[args].weakref_alive?
+         begin
            method_cache[args].value
+          rescue => e
+            errstat = GC.stat
+            binding.pry
+            raise
+          end
        else
          send(original_method_name, *args).tap do |r|
            method_cache[args] = WeakRef.new(Wrapper.new(r))
          end
        end

When the debugger breaks I printed the GC count:

[3] pry(#<Nanoc::Int::OutdatednessChecker>)> prestat[:count]
50
[4] pry(#<Nanoc::Int::OutdatednessChecker>)> errstat[:count]
51
Contributor

agross commented Jun 8, 2016

Yes, it seems GC is the culprit.

I added this:

+       require 'pry-byebug'
+       prestat = GC.stat
        if method_cache.key?(args) && method_cache[args].weakref_alive?
+         begin
            method_cache[args].value
+          rescue => e
+            errstat = GC.stat
+            binding.pry
+            raise
+          end
        else
          send(original_method_name, *args).tap do |r|
            method_cache[args] = WeakRef.new(Wrapper.new(r))
          end
        end

When the debugger breaks I printed the GC count:

[3] pry(#<Nanoc::Int::OutdatednessChecker>)> prestat[:count]
50
[4] pry(#<Nanoc::Int::OutdatednessChecker>)> errstat[:count]
51
@ddfreyne

This comment has been minimized.

Show comment
Hide comment
@ddfreyne

ddfreyne Jun 9, 2016

Member

Correct. I have a fix in #865, which uses rescue WeakRef::RefError rather than checking #weakref_alive?.

Member

ddfreyne commented Jun 9, 2016

Correct. I have a fix in #865, which uses rescue WeakRef::RefError rather than checking #weakref_alive?.

@ddfreyne ddfreyne closed this Jun 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment