0

I've got two servers... When deploying to them, they each call bundle exec rake assets:precompile. The result is two totally different md5 fingerprints for identical files:

from server 1:

-rw-r--r--  1 me  867345376  975106 Nov 30 10:22 vendor-1c2d7ad5dd44eab9d087.js

from server 2:

-rw-r--r--  1 me  867345376  975106 Nov 30 10:22 vendor-ec1d725a07fbfbdc2b9d.js

As you can see, they both have the same file size, and diffing the two files has no output (because they are identical). Any idea on how or why this could happen? This is problematic because the load balancer redirects to a server that potentially does not have the file with that fingerprint.

UPDATE: This is with rails 4.2.8 and sprockets 3.7.1

patrick
  • 9,290
  • 13
  • 61
  • 112

1 Answers1

0

There may be binary differences in the files, like line ending differences, that affect it but don't show in how you are invoking diff.

Try comparing them like in https://superuser.com/questions/125376/how-do-i-compare-binary-files-in-linux/

lsiebert
  • 667
  • 1
  • 5
  • 16
  • I did xxd -b with both files and diffed those outputs, and they were also identical. – patrick Nov 30 '17 at 20:16
  • I'm unsure what's going on then. I'd guess some sort of caching issue at this point, but you say the generated files are identical. You might try running bundle exec rake assets:clean and seeing if that fixes the issue. Also Sprockets 2.7.1 uses [Sha256](https://github.com/rails/sprockets/blob/v3.7.1/lib/sprockets/digest_utils.rb) and those look like 20 character digests, so I don't think those are md5. You could try to run sha256 on the files, either manually or using the rails console. – lsiebert Nov 30 '17 at 21:43
  • yeah I don't get it.. I found some documentation on how precompiling works, and it says it is doing: Digest::MD5.new.file(path).hexdigest... Yet if I do that over and over, I get a different hash every time. Digest::SHA256.file(path).hexdigest gives the me same fingerprint over and over, but it's definitely not the same as it gives a 64 character hash. – patrick Nov 30 '17 at 22:06
  • I also am confused if the fingerprint on tis file is coming from webpacker or sprockets. – patrick Nov 30 '17 at 22:07
  • Well webpacker doesn't come with 4.2 by default. Is it in your gemfile? You can run the rake command with -v to get verbose output and log that. You can also debug the actual rake task https://stackoverflow.com/questions/2663912/ruby-on-rails-debugging-rake-tasks#2663970 – lsiebert Nov 30 '17 at 23:32
  • hexdigest uses a random string as the input unless you supply one. try hexdigest("foo") in the rails console and you'll see the same result. – lsiebert Nov 30 '17 at 23:38
  • 1
    Finally tracked down the problem.. Webpack makes a 'vendor-[hash].js' file, where hash becomes the hash of the sum of all the vendor components's FULL PATH... So server 1 is /releases/12345 and server 2 is /releases/78990 because the timestamps of the deploys to not match...... So, now I have to I guess make a new question on here to figure out how to get [hash] to do relative paths. – patrick Dec 01 '17 at 00:17
  • were you able to find a solution for this? I am having same issue in our servers. Out of 6 servers 3 are having one fingerprint and other 3 are having a different one. – Arun Eapachen Feb 01 '19 at 09:09