Ticket #17 (assigned bug)

Opened 7 months ago

Last modified 1 month ago

gem_plugin interacts with other gems in a weird way

Reported by: evanweaver Assigned to: evanweaver (accepted)
Priority: minor Milestone: 1.2
Component: Mongrel Keywords:
Cc:

Description

Bugs: Browse | Submit New | Admin #16145 Not every gem is a plugin, is it? Date: 2007-12-06 11:47 Priority: 3 Submitted By: Jens Wille (jwille) Assigned To: Evan Weaver (evanweaver) Category: gem_plugin State: Open Summary: Not every gem is a plugin, is it?

Detailed description

After updating mongrel from 1.0.1 to 1.1.1, we experienced the following problem when starting script/server in one of our Rails applications. Coincidentally, gem_plugin has been updated, too, to 0.2.3 a few days ago. So I don't think this has anything to do with the mongrel update, but rather with gem_plugin.

Actually, my guess is that GemPlugin::Manager#load should really only consider those gems that actually have an init.rb file, thus avoiding such errors with non-gem_plugin capable gems. BTW: Should any GemPlugin?'s be loaded at all if +needs+ is just an empty hash?

----[ script/server error message ]----
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load
-- /usr/lib/ruby/gems/1.8/gems/activerdf-1.6.8/lib/activerdf/init.rb (MissingSourceFile)
        from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from XXX/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
        from XXX/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
        from XXX/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
        from /usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb:134:in `load'
        from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:166:in `each'
        from /usr/local/lib/site_ruby/1.8/rubygems/source_index.rb:166:in `each'
        from /usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb:112:in `load'
         ... 20 levels...
        from XXX/vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require'
        from XXX/vendor/rails/railties/lib/commands/server.rb:39
        from script/server:3:in `require'
        from script/server:3
---- snip ----

Could this be a possible fix?

----[ diff -u /usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb{~,} ]----
--- /usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb~     2007-12-06 17:34:58.000000000 +0100
+++ /usr/lib/ruby/gems/1.8/gems/gem_plugin-0.2.3/lib/gem_plugin.rb      2007-12-06 17:35:09.000000000 +0100
@@ -130,8 +130,9 @@
           # Previously was set wrong, we already have the correct gem path!
           #gem_dir = File.join(Gem.dir, "gems", "#{gem.name}-#{gem.version}")
           gem_dir = File.join(Gem.dir, "gems", path)
-
-          require File.join(gem_dir, "lib", gem.name, "init.rb")
+          init_rb = File.join(gem_dir, "lib", gem.name, "init.rb")
+
+          require init_rb if File.readable?(init_rb)
           @gems[gem.name] = gem_dir
         end
       end

cheers jens

Change History

05/27/08 04:14:18 changed by jwille

So... let me just rephrase the issue as far as I see it now (the original discussion is over here):

gem_plugin let's you define plugins for your gem by way of their gem dependencies. Hence, any gem that depends on both gem_plugin and mongrel is considered a mongrel plugin and loaded whenever mongrel starts. The problem now is that mongrel doesn't add itself to that dependency list, so that only gem_plugin remains. Which results in mongrel erroneously trying to load any gem that just happens to depend on gem_plugin.

E.g., activerdf depends on gem_plugin, but doesn't have the init.rb mongrel expects. Hence the MissingSourceFile? error.

The solution seems to be for mongrel to include itself as a required dependency for its plugins:

$ diff -u /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb{~,}
--- /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb~      2008-05-27 11:05:47.000000000 +0200
+++ /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb       2008-05-27 11:05:52.000000000 +0200
@@ -228,6 +228,8 @@
         end
       end

+      load_settings["mongrel"] = GemPlugin::INCLUDE
+
       GemPlugin::Manager.instance.load(load_settings)
     end

05/27/08 04:20:44 changed by evanweaver

Does that patch definitely interact well with the existing GemPlugins? that *are* supposed to get loaded?

05/27/08 04:20:54 changed by evanweaver

  • status changed from new to assigned.
  • milestone changed from 1.3 to 1.2.

05/27/08 04:51:48 changed by jwille

The only mongrel plugin I'm using is mongrel_cluster, which depends on both gem_plugin and mongrel, so it works. Any other gem that's supposed to be a mongrel plugin just has to depend on mongrel as well, don't you think? (I mean, just to get this straight: Isn't this how gem_plugin is supposed to work?)

How can I find out about those? How is a gem to be identified as mongrel plugin if it only depends on gem_plugin and not on mongrel?

The alternative, though not real solution (IMHO!) would be the one I proposed at first. That is to only try to load init.rb files that actually exist. This would apply to gem_plugin then and should definitely be compatible with any already existing plugins.

05/27/08 05:03:03 changed by evanweaver

I think you are right.

05/30/08 15:16:58 changed by airforce1