Skip to content
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
Closed

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

GregOnNet opened this issue Jun 8, 2016 · 7 comments
Milestone

Comments

@GregOnNet
Copy link

@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
Copy link
Contributor

@agross agross commented Jun 8, 2016

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

crash.log.txt

@ddfreyne
Copy link
Member

@ddfreyne 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
Copy link
Member

@ddfreyne ddfreyne commented Jun 8, 2016

Potential fix in #865.

@ddfreyne ddfreyne added this to the 4.2.1 milestone Jun 8, 2016
@agross
Copy link
Contributor

@agross 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
Copy link
Contributor

@agross agross commented Jun 8, 2016

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

@agross
Copy link
Contributor

@agross 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
Copy link
Member

@ddfreyne 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants