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

chdir makes code non-thread safe #180

Closed
draganm opened this issue Jan 19, 2015 · 3 comments
Closed

chdir makes code non-thread safe #180

draganm opened this issue Jan 19, 2015 · 3 comments

Comments

@draganm
Copy link

draganm commented Jan 19, 2015

Hi, while debugging my own code, stumbled over this in saml_message.rb:

  Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'schemas'))) do
      @schema = Nokogiri::XML::Schema(IO.read('saml-schema-protocol-2.0.xsd'))
      @xml = Nokogiri::XML(document.to_s)
   end

In a single threaded environment this is not an issue, but when there are more parallel threads running, there is a time window when the current working directory is changed for all threads. That could lead to random production failures on Rails using Puma for example ...

@pitbulk
Copy link
Collaborator

pitbulk commented Jan 19, 2015

What alternative you suggest?

@draganm
Copy link
Author

draganm commented Jan 20, 2015

This at least eliminates chdir at run-time - it only does chdir once when .rb files are required. Should also improve performance since it eliminates disk IO at validation time.

#181

@phlipper
Copy link
Contributor

This is resolved as of c8deef8

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

4 participants