Rubygems: undefined method `this'

Created on 22 Dec 2015  路  42Comments  路  Source: rubygems/rubygems

I believe commit a9c1aaffec0095081fd405ce78cfd689e937c1d7 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.

bug report

Most helpful comment

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

gem update --system

All 42 comments

@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.

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

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

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.

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

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

@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.

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.

@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

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

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.

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

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

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.

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.

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>'

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.

@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

@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.

Apparently self.all= has never been publicly supported even since it's inception in 09e026c19d68d11afe6b0ef61b8d0e33e7f88b73. 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?

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

@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.

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?

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.

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

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

@Solnse try @tenderlove fix

@Solnse I could not reproduce your problem using rubygems master (rvm rubygems master) - can you confirm it still happens for you? also if it does could you try @tenderlove's fix?

Hi, problem occurred again here after updating some gems. I am no longer using RVM (I'm using chruby).

Here is the stack (home path replaced with ~) :

$ invoker start ~/.invoker/invoker.ini
~/.rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:2158:in `method_missing': undefined method `this' for #<Gem::Specification:0x3fcea9084398 invoker-1.4.1> (NoMethodError)
    from ~/.rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:1057:in `find_active_stub_by_path'
    from ~/.rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:64:in `require'
    from ~/.gem/ruby/2.3.0/gems/invoker-1.4.1/bin/invoker:5:in `<top (required)>'
    from ~/.gem/ruby/2.3.0/bin/invoker:23:in `load'
    from ~/.gem/ruby/2.3.0/bin/invoker:23:in `<main>'
    from ~/.gem/ruby/2.3.0/bin/ruby_executable_hooks:15:in `eval'
    from ~/.gem/ruby/2.3.0/bin/ruby_executable_hooks:15:in `<main>'

Installed gems

actionmailer (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
actionpack (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
actionview (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
activejob (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
activemodel (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
activerecord (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
activesupport (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
addressable (2.4.0)
arel (6.0.3, 6.0.0)
ast (2.2.0, 2.1.0)
astrolabe (1.3.1)
autoprefixer-rails (6.3.1, 6.2.3, 6.1.2, 6.1.1, 6.0.2)
babel-source (5.8.35, 5.8.34, 5.8.26)
babel-transpiler (0.7.0)
bcrypt (3.1.10)
bigdecimal (1.2.8)
binding_of_caller (0.7.2)
bootstrap-sass (3.3.6, 3.3.5.1)
bourbon (4.2.6, 4.2.4)
bower-rails (0.10.0)
builder (3.2.2)
bundler (1.11.2)
bundler-unload (1.0.2)
byebug (8.2.2, 8.2.1, 6.0.2, 5.0.0)
capybara (2.6.2, 2.5.0)
celluloid (0.16.0)
CFPropertyList (2.2.8)
climate_control (0.0.3)
coffee-rails (4.1.1, 4.1.0)
coffee-script (2.4.1)
coffee-script-source (1.10.0, 1.9.1.1)
columnize (0.9.0)
concurrent-ruby (1.0.0)
connection_pool (2.2.0)
css_parser (1.3.7)
css_splitter (0.4.4)
debug_inspector (0.0.2)
devise (3.5.6, 3.5.3, 3.5.2)
did_you_mean (1.0.0)
diff-lcs (1.2.5)
docile (1.1.5)
dotenv (2.1.0, 2.0.2, 1.0.2)
dotenv-rails (2.1.0, 2.0.2)
em-hiredis (0.3.1, 0.3.0)
em-proxy (0.1.8)
erubis (2.7.0)
eventmachine (1.0.9.1, 1.0.8)
exception_notification (4.1.4, 4.1.3, 4.1.2, 4.1.1)
execjs (2.6.0, 2.5.2)
executable-hooks (1.3.2)
facter (2.4.4 universal-darwin)
factory_girl (4.5.0)
factory_girl_rails (4.6.0, 4.5.0)
faye-websocket (0.10.2, 0.10.0)
flutie (2.0.0)
formatador (0.2.5)
fuubar (2.0.0)
globalid (0.3.6, 0.3.5)
hirb (0.7.3)
hiredis (0.6.1, 0.5.2)
hitimes (1.2.3, 1.2.2)
htmlentities (4.3.4)
http-parser-lite (0.6.0)
http_accept_language (2.0.5)
i18n (0.7.0)
iniparse (1.4.2)
invoker (1.4.1)
io-console (0.4.5)
jbuilder (2.4.0, 2.2.16)
jquery-rails (4.1.0, 4.0.5, 4.0.3)
jquery-slick-rails (1.5.9.1, 1.5.8.2, 1.5.8.1)
jquery-turbolinks (2.1.0)
jquery-ui-rails (5.0.5)
json (1.8.3, 1.8.2)
loofah (2.0.3, 2.0.2)
macaddr (1.7.1)
mail (2.6.3)
mime-types (2.99, 2.6.2, 2.6.1)
mini_portile (0.6.2)
mini_portile2 (2.0.0)
minitest (5.8.4, 5.8.3, 5.8.1, 5.8.0, 5.7.0)
mmapped_string (0.1.0)
multi_json (1.11.2, 1.11.0)
net-telnet (0.1.1)
newrelic_rpm (3.14.2.312, 3.14.1.311)
nokogiri (1.6.7.2, 1.6.7.1, 1.6.6.4, 1.6.6.2)
orm_adapter (0.5.0)
parser (2.3.0.2, 2.3.0.pre.6, 2.2.3.0, 2.2.2.6)
pg (0.18.4, 0.18.3, 0.18.2)
pg_search (1.0.5)
power_assert (0.2.6)
powerpack (0.1.1)
premailer (1.8.6)
premailer-rails (1.9.0)
psych (2.0.17)
puma (2.16.0, 2.15.3, 2.13.4)
rack (1.6.4, 1.6.1)
rack-protection (1.5.3)
rack-test (0.6.3)
rails (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
rails-assets-autosize (3.0.15, 3.0.14)
rails-assets-filepicker-js (2.3.4, 2.3.1, 2.3.0)
rails-assets-google-maps (3.2.1, 3.1.0)
rails-assets-hammerjs (2.0.6, 2.0.4)
rails-assets-html5shiv (3.7.3)
rails-assets-jquery (2.2.0, 2.1.4)
rails-assets-jquery.transit (0.9.12)
rails-assets-respond (1.4.2)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.7, 1.0.6)
rails-html-sanitizer (1.0.3, 1.0.2)
rails_12factor (0.0.3)
rails_serve_static_assets (0.0.5, 0.0.4)
rails_stdout_logging (0.0.4)
railties (4.2.5.1, 4.2.5, 4.2.4, 4.2.3, 4.2.1)
rainbow (2.1.0, 2.0.0)
rake (10.5.0, 10.4.2)
rdoc (4.2.1, 4.2.0)
redis (3.2.2, 3.2.1)
responders (2.1.1, 2.1.0)
rspec (3.4.0, 3.3.0)
rspec-core (3.4.2, 3.4.1, 3.3.2)
rspec-expectations (3.4.0, 3.3.1)
rspec-mocks (3.4.1, 3.4.0, 3.3.2)
rspec-rails (3.4.2, 3.4.0, 3.3.3)
rspec-support (3.4.1, 3.3.0)
rspec_junit_formatter (0.2.2)
rubocop (0.36.0, 0.35.1, 0.34.1)
rubocop-rspec (1.3.1)
rubocop-rspec-focused (0.0.3)
ruby-progressbar (1.7.5)
rubydns (0.8.5)
rubygems-bundler (1.4.4)
sass (3.4.21, 3.4.20, 3.4.19, 3.4.18, 3.4.14)
sass-rails (5.0.4, 5.0.3)
sdoc (0.4.1)
shoulda-matchers (3.1.0, 2.8.0)
sidekiq (4.1.0, 4.0.1)
simple_form (3.2.1, 3.2.0, 3.1.1)
simplecov (0.11.1, 0.11.0, 0.10.0)
simplecov-html (0.10.0)
sinatra (1.4.7, 1.4.6)
slack-notifier (1.5.1, 1.5.0, 1.3.0)
slim (3.0.6)
slim-rails (3.0.1)
slim_lint (0.7.0, 0.6.1)
spring (1.6.2, 1.6.1, 1.6.0, 1.4.4, 1.3.6)
sprockets (3.5.2, 3.4.1, 3.4.0, 3.3.4, 3.1.0)
sprockets-es6 (0.8.2, 0.8.1)
sprockets-rails (3.0.1, 3.0.0, 2.3.3, 2.3.1)
sqlite3 (1.3.11)
sysexits (1.2.0)
systemu (2.6.5)
temple (0.7.6)
test-unit (3.1.5)
test_after_commit (0.4.2)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.2, 2.0.1, 1.4.1)
timecop (0.8.0)
timers (4.0.4)
tins (1.6.0)
turbolinks (2.5.3)
tzinfo (1.2.2)
uglifier (2.7.2, 2.7.1)
uuid (2.3.8)
warden (1.2.6, 1.2.4, 1.2.3)
web-console (3.1.1, 3.0.0, 2.2.1, 2.1.2)
websocket-driver (0.6.3, 0.6.2)
websocket-extensions (0.1.2)
xpath (2.0.0)
yomikomu (0.2.0)

env (home path replaced with ~) :

PATH=~/.gem/ruby/2.3.0/bin:~/.rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/bin:~/.rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
COMMAND_MODE=unix2003
TMPDIR=/var/folders/r5/jw6t1ym11dv0mj_33ksb9z0w0000gn/T/
XPC_FLAGS=0x0
HOME=~
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.VYohuLbynF/Render
LANG=fr_FR.UTF-8
TERM=xterm-256color
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.QDCLtJgG1o/Listeners
SECURITYSESSIONID=186a8
ITERM_PROFILE=Default
XPC_SERVICE_NAME=0
TERM_PROGRAM=iTerm.app
SHELL=/bin/zsh
ITERM_SESSION_ID=w0t0p1:C5A9677F-7808-494F-B0F1-38BDEFAA47B2
PWD=~/Documents/agorize
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x1
SHLVL=1
OLDPWD=~/Documents/agorize
ZSH=~/.oh-my-zsh
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
EDITOR=mate -w
_=/usr/bin/env
LC_CTYPE=fr_FR.UTF-8
RUBY_ROOT=~/.rubies/ruby-2.3.0
RUBYOPT=
RUBY_ENGINE=ruby
RUBY_VERSION=2.3.0
GEM_ROOT=~/.rubies/ruby-2.3.0/lib/ruby/gems/2.3.0
GEM_HOME=~/.gem/ruby/2.3.0
GEM_PATH=~/.gem/ruby/2.3.0:~/.rubies/ruby-2.3.0/lib/ruby/gems/2.3.0

I had success with the following workaround :

bundle clean
gem install executable-hooks

@tenderlove ,

def this; self; end

That fixes it.

@tenderlove ,

def this; self; end

Works

Where to you put "def this; self; end" ?

jeezs , looks like we both are on the same page. Any help on that one ?

@jeezs @sushantbajra

This is where you inject
def this; self; end

https://github.com/orenf/rubygems/commit/4a4b4758bd454b4f7525635aca5e8a00e47cab42

I just applied it to the Gem directly when I hit this issue. Not ideal, but it fixed my problem for now.

@orenf thanks now it is workng

What's the plan on getting this fixed without hacking the specification.rb file?

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

thanks that solved the issue!

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

gem update --system

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 methodthis' for # (NoMethodError)

Only options is to manually add @tenderlove fix

@garyv thanks! Worked like a charm

Was this page helpful?
0 / 5 - 0 ratings