rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
541 stars 97 forks source link

Crash on 2.0.0 with high request rate #99

Closed rintaun closed 11 years ago

rintaun commented 11 years ago

sinatra-assetpack seems to be causing a segmentation fault in ruby-2.0.0-p0 when the request rate is very high. It seems only to occur when there are > 1 files in a pack, and may be due to multi-threading.

The segfault seems to occur at random places in the code, but only occurs when the js helper is called in a view.

I can provide instructions on reproducing and provide backtraces upon request, but they're somewhat long to just paste in this issue.

j15e commented 11 years ago

Provide backtrace please, I doubt this be related to assetpack directly as I there is segault issues in other ruby libs with 2.0.0 (psych & other basic libs).

rintaun commented 11 years ago

https://gist.github.com/rintaun/5512860 That's from my actual application

https://gist.github.com/rintaun/5512891 is from a minimal application I wrote to reproduce this crash

j15e commented 11 years ago

Thanks, this part (sinatra/assetpack/buster_helpers.rb:8) is not very optimized as it calculate the full content hash on every request (I think), we should look into it.

      # Returns the MD5 for all of the files concatenated together
      def cache_buster_hash(*files)
        content = files.sort.map { |f| File.read(f).to_s if f.is_a?(String) && File.file?(f) }.compact
        Digest::MD5.hexdigest(content.join) if content.any? # culprit
      end
j15e commented 11 years ago

Before we were using the files mtime but it's not as accurate. We should cache it in memory using an instance variable or add a manifest as suggested in #82

j15e commented 11 years ago

Without new informations available, Ill close this one as it seems to be a ruby-2.0.0-p0 specific bug that should be fixed in ruby-2.0.0-p195.