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

Gyoku is not threadsafe #29

Closed
pschambacher opened this issue Jun 13, 2013 · 10 comments
Closed

Gyoku is not threadsafe #29

pschambacher opened this issue Jun 13, 2013 · 10 comments

Comments

@pschambacher
Copy link

Sometimes when using gyoku through Savon we get an exception like so:

NoMethodError: undefined method `upcase' for nil:NilClass

vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:5:in `__singleton__' org/jruby/RubyString.java:3037:in `gsub' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:5:in `__singleton__' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:11:in `__singleton__' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku/xml_key.rb:24:in `create'
vendor/bundle/jruby/1.9/gems/gyoku-1.0.0/lib/gyoku.rb:8:in `xml_tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/message.rb:22:in `to_s'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:146:in `tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:35:in `to_s' org/jruby/RubyProc.java:249:in `call' (
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:170:in `_nested_structures'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:63:in `tag!'
vendor/bundle/jruby/1.9/gems/builder-3.0.4/lib/builder/xmlbase.rb:62:in `tag!'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:146:in `tag'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/builder.rb:33:in `to_s'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/operation.rb:72:in `build_request'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/operation.rb:48:in `call'
vendor/bundle/jruby/1.9/gems/savon-2.1.0/lib/savon/client.rb:38:in `call'

I'm not exactly sure why this happen, probably the result is not as gyoku expect it but a proper error would be nicer than a NoMethodError.

@rubiii
Copy link
Contributor

rubiii commented Jun 13, 2013

can you provide an example hash to reproduce this problem?

@rubiii
Copy link
Contributor

rubiii commented Jun 30, 2013

closing this because it can't be reproduced. feel free to reopen if you can provide code or a failing test. thanks.

@rubiii rubiii closed this as completed Jun 30, 2013
@fsw0723
Copy link

fsw0723 commented Sep 17, 2013

It happens only when we try to make savon requests in threads. Fails for exactly same reason.

@pschambacher
Copy link
Author

FYI we're using Savon in threads too.

@anandagrawal84
Copy link

@pierre-schambacher did you find the cause of this? How are you managing with it? Its quite intermittent and not reproducible deterministically.

@pschambacher
Copy link
Author

@anandagrawal84 we're using this in a pulling system that gets called every few seconds. Since it does not happen very often and since we can miss a call, we haven't done anything. We just get a few errors now and then in NewRelic.

@kafkasbug
Copy link

We are getting the same error for a program we use. The following test reproduces the error on jruby 1.7.11 (1.9.3p392):

require 'gyoku'
def convert_all(array)
  array.map{|s| Gyoku.xml_tag s}
end
a = (1..20).map {|i| "hello_world#{i}".to_sym}
threads = (1..200).map do |i|
  Thread.new do
    sleep 1
    convert_all a
  end
end
threads.each {|t| t.join}
puts "all done"

@tjarratt
Copy link
Contributor

Pretty sure I've been able to isolate this to using the $1 global variable here in the key converter. It's pretty clear this isn't thread safe.

My current understanding is that Gyoku makes no attempt at being thread safe, but this seems like a pretty reasonable request to make. The first changes that need to be made are to rewrite the key converters to not use the $1 global variable when using regexes. I'd like to do this myself, but I'm finding that my time is really at a premium these days and I'm unsure when I'll be able to find time.

If someone is interested in issuing a pull request for this, I'd be more than happy to review and merge it!

@tjarratt tjarratt reopened this Aug 27, 2014
@tjarratt tjarratt changed the title Undefined method upcase for nil:NilClass Gyoku is not threadsafe Aug 27, 2014
@perlun
Copy link
Contributor

perlun commented Sep 11, 2014

This thread has some insight into the underlying problem, and why $1 in a lambda/proc is not threadsafe: https://jira.codehaus.org/browse/JRUBY-6754

@tjarratt
Copy link
Contributor

Closing thanks to #46 and d329e39 -- this should be available in Gyoku v1.2.1. Thank you @perlun, @pschambacher and @kafkasbug for raising this issue!

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

No branches or pull requests

7 participants