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

Use autoload to be threadsafe #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kirs
Copy link

@kirs kirs commented Sep 7, 2020

The current implementation of const_missing is not thread safe and it triggers exceptions like:

NoMethodError: undefined method `implementation' for HTTP::CookieJar::AbstractStore:Class
  /app/data/bundler/ruby/2.6.0/gems/http-cookie-1.0.3/lib/http/cookie_jar.rb:38:in `get_impl'
  /app/data/bundler/ruby/2.6.0/gems/http-cookie-1.0.3/lib/http/cookie_jar.rb:74:in `initialize'
  /app/data/bundler/ruby/2.6.0/gems/rest-client-2.1.0/lib/restclient/request.rb:339:in `new'
  /app/data/bundler/ruby/2.6.0/gems/rest-client-2.1.0/lib/restclient/request.rb:339:in `process_cookie_args!'
  /app/data/bundler/ruby/2.6.0/gems/rest-client-2.1.0/lib/restclient/request.rb:86:in `initialize'
  /app/data/bundler/ruby/2.6.0/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `new'
  /app/data/bundler/ruby/2.6.0/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `execute'
  /app/data/bundler/ruby/2.6.0/gems/rest-client-2.1.0/lib/restclient/resource.rb:51:in `get'

I tried to make that const_missing thread safe by using a mutex but I don't think it's possible because of circular dependencies.

A colleague of mine suggested that I leverage autoload which is thread safe.

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.

None yet

1 participant