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

Running DomainName multi-threaded leads to Stack Errors #2

Closed
wants to merge 1 commit into from
Closed

Running DomainName multi-threaded leads to Stack Errors #2

wants to merge 1 commit into from

Conversation

chainum
Copy link

@chainum chainum commented Mar 18, 2012

I'm running Mechanize (https://github.com/tenderlove/mechanize) multi-threaded using Sidekiq (https://github.com/mperham/sidekiq).

Mechanize pulls in the DomainName-gem to handle (for example) parsing of cookie domain names. Apparently due to the large size (~4000 items) of the hash in lib/domain_name/etld_data.rb stack errors occur. This does not happen when in single-threaded mode though.

Changing the hash to be first instantiated and then adding the respective hash items seems to solve it.

The tests pass on 1.9.3-p125 and 1.9.2-p290. If necessary I can see if I can set up a sample Rails-app with Mechanize/Sidekiq so you can reproduce the issue in multi-threaded mode yourself.

@knu
Copy link
Owner

knu commented Mar 19, 2012

The patch is far from acceptable because eliminating caching in a class variable means a large hash table is created every time the library tries to look etld_data up.

I don't really get the problem but will guarding the initialization with a mutex do?

require 'thread'

# ...
def self.etld_data
  Thread.exclusive {
    @@etld_data ||= {
      # ...
    }
  }
end

@chainum
Copy link
Author

chainum commented Mar 19, 2012

Hey!

I tried to keep the caching/memoization but that didn't fix the StackError.

The problem is basically the following:

  • I run mechanize in multi-threaded mode using Sidekiq.
  • I post to a form using mechanize and it's cookie handling-logic uses DomainName to parse the domain of the cookie.
  • When it parses the cookie DomainName.etld_data is loaded which crashes the Sidekiq-processors due to Stack Errors - they completely die.

An interesting thing is that I removed ~3k entries or so from etld_data.rb (leaving only 1k left) and somehow the Stack Errors stopped.

Using my solution (thus without the class-variable/memoization) worked for all the 4k entries though.

I'll do some more investigation later tonight and see if I can get it to work while preserving the class-variable and the cache/memoization.

@knu
Copy link
Owner

knu commented Mar 19, 2012

I think I'll just constify the table so the initialization won't occur in multiple threads simultaneously.

@knu knu closed this in c23fa9f Apr 6, 2012
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

2 participants