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

Fix after boot thread-safety issue #585

Merged
merged 1 commit into from
Mar 4, 2014
Merged

Fix after boot thread-safety issue #585

merged 1 commit into from
Mar 4, 2014

Conversation

etehtsea
Copy link
Contributor

Demo to reproduce: https://gist.github.com/etehtsea/9143028

Example stacktrace:

[INFO ] TorqBox::Server  - TorqBox 0.1.7 starting...
[INFO ] org.projectodd.wunderboss.web.WebComponent  - Undertow listening on localhost:8080
[INFO ] org.projectodd.wunderboss.web.WebComponent  - Started web context /
[ERROR] io.undertow.request  - Blocking request failed HttpServerExchange{ GET /}
org.jruby.exceptions.RaiseException: (NameError) method "OPTIONS   /" already exists and cannot be used as an unbound method name
    at RUBY.generate_api_method(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/endpoint.rb:26)
    at RUBY.initialize(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/endpoint.rb:50)
    at RUBY.route(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:353)
    at RUBY.options(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:396)
    at RUBY.add_head_not_allowed_methods_and_options_methods(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:578)
    at org.jruby.RubyHash.each(org/jruby/RubyHash.java:1338)
    at RUBY.add_head_not_allowed_methods_and_options_methods(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:572)
    at RUBY.initialize(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:527)
    at RUBY.compile(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:29)
    at RUBY.call(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:37)
    at RUBY.call(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/gems/rack-1.5.2/lib/rack/commonlogger.rb:33)
[ERROR] io.undertow.request  - Blocking request failed HttpServerExchange{ GET /}
org.jruby.exceptions.RaiseException: (NameError) method "   /" already exists and cannot be used as an unbound method name
    at RUBY.generate_api_method(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/endpoint.rb:26)
    at RUBY.initialize(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/endpoint.rb:50)
    at RUBY.route(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:353)
    at RUBY.add_head_not_allowed_methods_and_options_methods(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:586)
    at org.jruby.RubyHash.each(org/jruby/RubyHash.java:1338)
    at RUBY.add_head_not_allowed_methods_and_options_methods(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:572)
    at RUBY.initialize(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:527)
    at RUBY.compile(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:29)
    at RUBY.call(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:37)
    at RUBY.call(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/gems/rack-1.5.2/lib/rack/commonlogger.rb:33)
[ERROR] io.undertow.request  - Blocking request failed HttpServerExchange{ GET /}
org.jruby.exceptions.RaiseException: (NameError) method 'PUT POST DELETE PATCH   /' not defined in Grape::Endpoint
    at org.jruby.RubyModule.remove_method(org/jruby/RubyModule.java:2344)
    at RUBY.generate_api_method(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/endpoint.rb:30)
    at RUBY.initialize(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/endpoint.rb:50)
    at RUBY.route(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:353)
    at RUBY.add_head_not_allowed_methods_and_options_methods(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:586)
    at org.jruby.RubyHash.each(org/jruby/RubyHash.java:1338)
    at RUBY.add_head_not_allowed_methods_and_options_methods(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:572)
    at RUBY.initialize(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:527)
    at RUBY.compile(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:29)
    at RUBY.call(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/bundler/gems/grape-466579209276/lib/grape/api.rb:37)
    at RUBY.call(/Users/kes/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/gems/rack-1.5.2/lib/rack/commonlogger.rb:33)
127.0.0.1 - - [22/Feb/2014 00:43:26] "GET / " 200 5 2.7050
127.0.0.1 - - [22/Feb/2014 00:43:26] "GET / " 200 5 2.8660
127.0.0.1 - - [22/Feb/2014 00:43:26] "GET / " 200 5 2.8530
127.0.0.1 - - [22/Feb/2014 00:43:26] "GET / " 200 5 2.8620
127.0.0.1 - - [22/Feb/2014 00:43:26] "GET / " 200 5 2.8560
127.0.0.1 - - [22/Feb/2014 00:43:26] "GET / " 200 5 2.8740

@dblock
Copy link
Member

dblock commented Feb 22, 2014

This is good. It does need an update to CHANGELOG, please. Please also move the require 'thread' into https://github.com/intridea/grape/blob/master/lib/grape.rb.

@etehtsea
Copy link
Contributor Author

@dblock done

@@ -34,7 +36,7 @@ def change!
end

def call(env)
compile unless instance
LOCK.synchronize { compile } unless instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this again, I think this is actually incorrect. If you have two threads coming into the lock you're going to compile twice. The unless instance should also be checked inside the lock or, better, rewrite compile as @instance ||= new (I think this won't have side-effects, but I am not sure where else compile is called).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Updated.

dblock added a commit that referenced this pull request Mar 4, 2014
Fix after boot thread-safety issue
@dblock dblock merged commit 70db3f7 into ruby-grape:master Mar 4, 2014
@dblock
Copy link
Member

dblock commented Mar 4, 2014

Merged, thanks.

@dblock dblock mentioned this pull request Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants