Rails 3 - Error too long file name

We have an online store that runs on the Rails 3 Spree platform. Recently, customers started reporting strange errors during the inspection, and after analyzing the production logs, I found the following error:

Errno :: ENAMETOOLONG (the file name is too long - / var / www / store / tmp / cache / UPS ground-R43362140-US-Nj FlorhamPark07932-1025786194_1%7C1025786087_1%7C1025786089_15%7C1025786146_4%7C1025786147_3%7C1025786098_3%7C1025786099_4%7C1025786100_2%7C1025786114_1%7C1025786120_1%7C1025786121_1%7C1025786181_1%7C1025786182_1%7C1025786208_120110412-2105-1e14pq5.lock)

I am not sure why this file name took so long, and if this error applies to Rails or Spree. Also, I am not very familiar with the Rails caching system. I would appreciate any help on how I can solve this problem.

+4
source share
5 answers

I assume that you are using spree_active_shipping, as this is similar to the cache id for the quote sent by UPS. This will happen when someone creates an order in which there are many line items. With enough positions, this of course will create a very large file name for the cache, which will give you an error.

One option is to use memcache or redis for your Rails.cache instead of using the file system cache. Another would be to change the algorithm that the cache_key generates in the / models / active _shipping.rb application in the spree_active_shipping gem.

The last option would probably be the best, and you could just create the generated cache key via a hash, like MD5 or SHA1. This way you get the predicted cache key length.

Indeed, this should be fixed in spree_active_shipping, although it should not generate unpredictably long cache keys, even if you use the keystore, this lost memory.

+5
source

This has more to do with your file system. Either configure a file system that supports longer file names, or change the software to improve the file names (md5? Timestamp? Unique id?).

+3
source

Maybe this help:

config.assets.digest and config.assets.debug cannot be true

This is a bug: https://github.com/rails/jquery-rails/issues/33

+2
source

I am using rails 3.2.x and have the same problem. As a result, I create an MD5 digest in the helper view method used to generate the cache key.

 FILENAME_MAX_SIZE = 200 def cache_key(prefix, params) params = Array.wrap(params) if params.instance_of?(String) key = "#{prefix}/" << params.entries.sort { |a,b| a[0].to_s <=> b[0].to_s }.map { |k,v| "#{k}:#{v}"}.join(',').to_s if URI.encode_www_form_component(key).size > FILENAME_MAX_SIZE key = Digest::MD5.hexdigest(key) end key end 

Here I have to check the length of the key value in URI encoding with URI.encode_www_form_component(key).size , because, as you can see in my case, the cache key is generated using delimiters : and URI.encode_www_form_component(key).size Rails encodes the key before caching the results.

I took the link to the transfer request .

0
source

Do you use paperclip gem? If so, this question is resolved: https://github.com/thoughtbot/paperclip/issues/1246 .

Update your paperclip instance to the latest version.

0
source

Source: https://habr.com/ru/post/1347998/


All Articles