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

undefined method `this' #1420

Closed
Solnse opened this Issue Dec 22, 2015 · 42 comments

Comments

Projects
None yet
@Solnse
Copy link

Solnse commented Dec 22, 2015

I believe commit a9c1aaf introduced a bug, discovered while trying to run passenger standalone 5.0.23 with rubygems 2.5.1 and ruby 2.2.4.

lib/rubygems/specification.rb:1056 stub.this

  /home/chad/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:2158:in `method_missing': undefined method `this' for #<Gem::Specification:0xf85df4 passenger-5.0.23> (NoMethodError)
        from /home/chad/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1056:in   find_active_stub_by_path'

server fails to start.

Solnse pushed a commit to Solnse/rubygems that referenced this issue Dec 22, 2015

@evanphx

This comment has been minimized.

Copy link
Member

evanphx commented Dec 22, 2015

@Solnse I believe you're getting some weird cross usage of Rubygems. .this is defined in that same commit, so I assume it should be used.

@evanphx

This comment has been minimized.

Copy link
Member

evanphx commented Dec 22, 2015

Looking at the code, the issue is why a normal Specification is being found when only stubs should be. /cc @tenderlove

@tenderlove

This comment has been minimized.

Copy link
Contributor

tenderlove commented Dec 22, 2015

@Solnse that method should only ever return stub objects. Can you show me how to make it return not stub objects?

@Solnse

This comment has been minimized.

Copy link

Solnse commented Dec 23, 2015

I have not done anything strange. I was simply upgrading to ruby 2.2.4. I'll see if I can replicate the issue on another machine.

@tenderlove

This comment has been minimized.

Copy link
Contributor

tenderlove commented Dec 23, 2015

@Solnse can you give us a way to reproduce it? Will a simple rack app with passenger standalone be enough to reproduce the issue?

@Solnse

This comment has been minimized.

Copy link

Solnse commented Dec 23, 2015

Yes, happens with a fresh new app. Here's the gist of the specifics I used to create a new app that fails.

rails new simple_app

@tenderlove

This comment has been minimized.

Copy link
Contributor

tenderlove commented Dec 24, 2015

@Solnse thanks for the reproduction steps. I wasn't able to reproduce it, but I suspect it's something to do with either RVM (I'm using rbenv), or the ruby_executable_hooks thing that's in your stack trace. Can you try running the passenger binfile directly like this:

$ /home/chad/.rvm/gems/ruby-2.2.4/bin/passenger

I suspect that you have two versions of rubygems loaded somehow, though I'm not sure how.

@Solnse

This comment has been minimized.

Copy link

Solnse commented Dec 24, 2015

I'll try it when I get to my machine in the morning. I am not sure about the double load though. I did some troubleshooting today and it doesn't happen with Ruby 2.1.8, nor does it happen when using Webrick and 2.2.4. Just seems to be the 2.2.4/passenger combo.

On 2.1.8, it never enters that method. On 2.2.4, I can't figure out where it is getting the spec object at all, the setter possibilities all look nil, but inspecting the spec variable at the end of the method does show the specification object. I'll see what I can test in the morning and get back to you.

@Solnse

This comment has been minimized.

Copy link

Solnse commented Dec 24, 2015

@tenderlove running it directly still produces the same error.

I added some debug code to the method to look at the objects, and it's confusing to me why the specification object is even created. But, I think the bigger question is why the method is being called at all... perhaps because of line 62 in core_ext/kernel_require.rb

here is the debug code and result if you want to see the objects: debug_find_active_stub_by_path

@Solnse

This comment has been minimized.

Copy link

Solnse commented Dec 24, 2015

@tenderlove downgraded rubygems to 2.4.8 and passenger starts no problem. successful start with rubygems 2.4.8

@Solnse

This comment has been minimized.

Copy link

Solnse commented Dec 24, 2015

Correction to my earlier comment, it didn't happen in ruby 2.1.8 because I was also using rubygems 2.4.8, using ruby 2.1.8 and rubygems 2.5.1 the same error occurs.

ruby 2.2.4 / rubygems 2.5.1 = fail
ruby 2.1.8 / rubygems 2.5.1 = fail
ruby 1.9.3 / rubygems 2.5.1 = fail

when using rubygems 2.4.8, those 3 ruby versions succeed starting passenger.

I also reproduced the same results using passenger 4.0.60 and 5.0.23.

A co-worker who uses rvm has reproduced this error on his machine using ruby 2.2.4 and rubygems 2.5.1.

Edit:
Another co-worker who uses rbenv successfully started passenger using ruby 2.2.2 and rubygems 2.5.1. So, it looks like your thought is correct. It appears to be a rvm issue with the 2.5.1 version of rubygems. I guess the question is now if rubygems is planning to support rvm going forward or not.

@krainboltgreene

This comment has been minimized.

Copy link
Member

krainboltgreene commented Dec 30, 2015

I will definitely try to make that happen. Any thoughts @mpapis?

@mpapis

This comment has been minimized.

Copy link
Contributor

mpapis commented Dec 30, 2015

this happens because of incompatibility in https://github.com/rvm/bundler-unload/blob/master/lib/bundler-unload.rb#L23-L30 _all returns using stubs.map(&:to_spec) and all= sets it with @@all = @@stubs = specs - which does not look compatible for me

I think rubygems would need to fix self.all= - I do not see way to fix it in bundler-unload as self.stubs has no equivalent self.stubs= - I would be happy to provide implementation using self.stubs= if it would be made available in rubygems

@krainboltgreene

This comment has been minimized.

Copy link
Member

krainboltgreene commented Dec 30, 2015

Interesting. I'm not sure I understand the situation completely, but I'll see if I can't get someone to do a PR for a fix.

@mpapis

This comment has been minimized.

Copy link
Contributor

mpapis commented Dec 30, 2015

I might have been wrong with stating there was no way for bundler-unload to fix it, try: https://gist.github.com/mpapis/bac6163f8855e12f7833 - I still think that current implementation of all= is broken, in current state it's more like stubs= which is missing.

@ybart

This comment has been minimized.

Copy link

ybart commented Dec 31, 2015

I'm experiencing a similar issue, so I tried to apply @mpapis's patch on ~/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/bundler-unload-1.0.2/lib/bundler-unload.rb then rvm reload. It seems bundler is now getting stubs where it expects specs :

~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:77:in `block in rubygems_spec': undefined method `executables' for #<Gem::StubSpecification:0x007f92019132d8> (NoMethodError)
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:77:in `each'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:77:in `detect'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:77:in `rubygems_spec'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:48:in `candidate?'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:92:in `setup'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:124:in `check'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems-bundler/noexec.rb:131:in `<top (required)>'
    from ~/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
    from ~/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
    from ~/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/rubygems-bundler-1.4.4/lib/rubygems_executable_plugin.rb:4:in `block in <top (required)>'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:50:in `block in run'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:49:in `each'
    from ~/.rvm/gems/ruby-2.3.0@global/gems/executable-hooks-1.3.2/lib/executable-hooks/hooks.rb:49:in `run'
    from ~/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:10:in `<main>'
@indirect

This comment has been minimized.

Copy link
Member

indirect commented Dec 31, 2015

As far as I know, the current version of RubyGems does not provide a supported public API for all= since 2.0+. Given that, I don't think bundler-unload will be supported on RubyGems 2.

@mpapis

This comment has been minimized.

Copy link
Contributor

mpapis commented Jan 4, 2016

@indirect does it mean that any software using all= will not be supported? for example Bundler uses the same method here: setup => replace_entrypoints => stub_rubygems

@ybart please open a ticket for https://github.com/rvm/rubygems-bundler with steps to reproduce, I will work on a fix for this problem

@ybart

This comment has been minimized.

Copy link

ybart commented Jan 4, 2016

@mpapis Sorry, in the meantime I've reinstalled RVM and after multiple attempts I was not able to reproduce the issue after installing RVM with both Ruby 2.3.0 and Ruby 2.2.4 and my usual environment. Unfortunately I haven't saved my environment and the installed gem list so I could not provide much more information.

@tenderlove

This comment has been minimized.

Copy link
Contributor

tenderlove commented Jan 6, 2016

Apparently self.all= has never been publicly supported even since it's inception in 09e026c. The comment is pretty clear (I think). I can add a warning that it will be removed in Rubygems 3.0.

In the mean time, I think this patch would fix this case:

diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 726d301..a010bb0 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -2999,6 +2999,8 @@ open-ended dependency on #{dep} is not recommended

   extend Gem::Deprecate

+  def this; self; end
+
   # TODO:
   # deprecate :has_rdoc,            :none,       2011, 10
   # deprecate :has_rdoc?,           :none,       2011, 10

Specs and stubs should quack the same otherwise, so the two should be interchangeable (though I would prefer if they weren't and we used delegate objects instead). Can someone who can repro try my patch?

@mpapis

This comment has been minimized.

Copy link
Contributor

mpapis commented Jan 7, 2016

@tenderlove so does it mean Bundler will have to hack RubyGems in 3.0 or there will be added new supported way?

@indirect

This comment has been minimized.

Copy link
Member

indirect commented Jan 7, 2016

@mpapis RubyGems has never supported all= as a public interface, but the RubyGems team provided a special exception for Bundler in a patch that they sent us: https://github.com/bundler/bundler/blob/master/lib/bundler/rubygems_integration.rb#L325-L333

Unless the RubyGems team changes their minds, there is no public all= method.

@mpapis

This comment has been minimized.

Copy link
Contributor

mpapis commented Jan 7, 2016

let me rephrase the question, what is next for RubyGems 3.0 will Bundler (and others) get another supported/unsupported method or we will need to hack RubyGems to make this work?

@indirect

This comment has been minimized.

Copy link
Member

indirect commented Jan 7, 2016

I don't think there is a clear plan right now. In the future, Bundler will be part of RubyGems, so it seems like there will not ever be a need for a public all= method.

@mpapis

This comment has been minimized.

Copy link
Contributor

mpapis commented Jan 7, 2016

this means there will be also no need for bundler-unload(rubygems-bundler) - problem solved, thank you

@Solnse

This comment has been minimized.

Copy link

Solnse commented Jan 7, 2016

So, perhaps then my original suggested fix should be the band-aid until then?

@segiddins

This comment has been minimized.

Copy link
Member

segiddins commented Apr 5, 2016

@ezekg this ought to be fixed in 2.6.3, which was released last night.

@gburanov

This comment has been minimized.

Copy link

gburanov commented Aug 6, 2016

thanks that solved the issue!

@garyv

This comment has been minimized.

Copy link

garyv commented Oct 26, 2016

Updating ruby gems will this fix issue on most systems now.

gem update --system
@meetme2meat

This comment has been minimized.

Copy link

meetme2meat commented Nov 22, 2016

Still the same with rubygems 2.5.1.

/Users/Idyllic/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:2158:in method_missing': undefined method this' for #<Gem::Specification:0x3fc85581b520 capistrano-3.6.1> (NoMethodError)

Only options is to manually add @tenderlove fix

@antoniosb

This comment has been minimized.

Copy link

antoniosb commented Mar 8, 2017

@garyv thanks! Worked like a charm

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