Image assets not served in production mode #1761

Closed
stevehodgkiss opened this Issue Jun 18, 2011 · 5 comments

Comments

Projects
None yet
2 participants
@stevehodgkiss
Contributor

stevehodgkiss commented Jun 18, 2011

I get no response body for images running with precompiled assets or without. I've tried to recreate the issue it from scratch but it works fine in a rails app with only 1 or 2 assets (the same ones that won't get served here). The precompiled images open finder ok, they just doesn't get served.

Full response:

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 0
Content-Md5: 39228bfa8d3b5a8327d7d221cab0de6d
Cache-Control: public, max-age=31536000
Last-Modified: Sat, 18 Jun 2011 13:54:30 GMT
Etag: "39228bfa8d3b5a8327d7d221cab0de6d"
X-Ua-Compatible: IE=Edge,chrome=1
X-Sendfile: /Users/steve/projects/railsapp/app/assets/images/subnav1-bg.png
X-Runtime: 0.001175
Date: Sat, 18 Jun 2011 16:10:16 GMT
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Age: 702
X-Rack-Cache: fresh
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close


Running with the latest rails and sprockets produces the same results:

gem 'rails', :git => "https://github.com/rails/rails.git", :branch => "3-1-stable"
gem 'sprockets', :git => "https://github.com/sstephenson/sprockets.git"

Any ideas what could be causing this?

@stevehodgkiss

This comment has been minimized.

Show comment
Hide comment
@stevehodgkiss

stevehodgkiss Jun 18, 2011

Contributor

The response from a fresh rails app in production mode differs in that it doesn't have the sendfile header.

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 6646
Content-Md5: 9c0a079bdd7701d7e729bd956823d153
Cache-Control: public, must-revalidate
Last-Modified: Sat, 18 Jun 2011 16:10:53 GMT
Etag: "9c0a079bdd7701d7e729bd956823d153"
X-Ua-Compatible: IE=Edge,chrome=1
X-Runtime: 0.014684
Date: Sat, 18 Jun 2011 18:45:02 GMT
X-Content-Digest: 501d6b0108b930264e19f37cb8ee6c8222d4f30d
Age: 0
X-Rack-Cache: miss, store
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close

PNG

...png data

On my production server with nginx/passenger and the sendfile header it still doesn't return the content.

HTTP/1.1 200 OK
Content-Type: image/png
Connection: close
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7
Content-Length: 0
Content-Md5: 27a9df45d0dbd65832db54155874afdb
Cache-Control: no-cache
Last-Modified: Sat, 18 Jun 2011 14:42:52 GMT
Etag: "27a9df45d0dbd65832db54155874afdb"
X-Ua-Compatible: IE=Edge,chrome=1
X-Sendfile: /home/rails/railsapp/app/assets/images/icons/flickr.png
X-Runtime: 0.036605
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Date: Sat, 18 Jun 2011 18:48:38 GMT
Age: 0
X-Rack-Cache: stale, valid, store
Server: nginx/1.0.0 + Phusion Passenger 3.0.7 (mod_rails/mod_rack)
Contributor

stevehodgkiss commented Jun 18, 2011

The response from a fresh rails app in production mode differs in that it doesn't have the sendfile header.

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 6646
Content-Md5: 9c0a079bdd7701d7e729bd956823d153
Cache-Control: public, must-revalidate
Last-Modified: Sat, 18 Jun 2011 16:10:53 GMT
Etag: "9c0a079bdd7701d7e729bd956823d153"
X-Ua-Compatible: IE=Edge,chrome=1
X-Runtime: 0.014684
Date: Sat, 18 Jun 2011 18:45:02 GMT
X-Content-Digest: 501d6b0108b930264e19f37cb8ee6c8222d4f30d
Age: 0
X-Rack-Cache: miss, store
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close

PNG

...png data

On my production server with nginx/passenger and the sendfile header it still doesn't return the content.

HTTP/1.1 200 OK
Content-Type: image/png
Connection: close
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7
Content-Length: 0
Content-Md5: 27a9df45d0dbd65832db54155874afdb
Cache-Control: no-cache
Last-Modified: Sat, 18 Jun 2011 14:42:52 GMT
Etag: "27a9df45d0dbd65832db54155874afdb"
X-Ua-Compatible: IE=Edge,chrome=1
X-Sendfile: /home/rails/railsapp/app/assets/images/icons/flickr.png
X-Runtime: 0.036605
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Date: Sat, 18 Jun 2011 18:48:38 GMT
Age: 0
X-Rack-Cache: stale, valid, store
Server: nginx/1.0.0 + Phusion Passenger 3.0.7 (mod_rails/mod_rack)
@stevehodgkiss

This comment has been minimized.

Show comment
Hide comment
@stevehodgkiss

stevehodgkiss Jun 18, 2011

Contributor

This only happens when the active record railtie has been commented out (I'm using mongoid) and the tmp dir has been deleted to sweep Rack::Cache's cache.

Steps to reproduce:

  • rails new asset-pipeline-issue -JT
  • cd asset-pipeline-issue
  • rails s -e production

Attempt to GET /assets/rails.png and it will return

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 6646
Content-Md5: 9c0a079bdd7701d7e729bd956823d153
Cache-Control: no-cache
Last-Modified: Sat, 18 Jun 2011 19:40:24 GMT
Etag: "9c0a079bdd7701d7e729bd956823d153"
X-Ua-Compatible: IE=Edge,chrome=1
X-Runtime: 0.014243
X-Content-Digest: 501d6b0108b930264e19f37cb8ee6c8222d4f30d
Date: Sat, 18 Jun 2011 19:43:09 GMT
Age: 0
X-Rack-Cache: stale, valid, store
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close

�PNG

pngdata...
  • Comment out require "active_record/railtie" in application.rb.
  • If you run the server again now and GET /assets/rails.png it will work as above, so delete the tmp directory.
  • rails s -e production

Attempt to GET /assets/rails.png and it will return

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 0
Content-Md5: 9c0a079bdd7701d7e729bd956823d153
Cache-Control: public, must-revalidate
Last-Modified: Sat, 18 Jun 2011 19:40:24 GMT
Etag: "9c0a079bdd7701d7e729bd956823d153"
X-Ua-Compatible: IE=Edge,chrome=1
X-Sendfile: /Users/steve/projects/tmp/asset-pipeline-issue/app/assets/images/rails.png
X-Runtime: 0.042701
Date: Sat, 18 Jun 2011 19:46:55 GMT
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Age: 0
X-Rack-Cache: miss, store
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close

I think this is something to do with the connection middleware proxy that comes with activerecord, but that's just a guess.

Contributor

stevehodgkiss commented Jun 18, 2011

This only happens when the active record railtie has been commented out (I'm using mongoid) and the tmp dir has been deleted to sweep Rack::Cache's cache.

Steps to reproduce:

  • rails new asset-pipeline-issue -JT
  • cd asset-pipeline-issue
  • rails s -e production

Attempt to GET /assets/rails.png and it will return

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 6646
Content-Md5: 9c0a079bdd7701d7e729bd956823d153
Cache-Control: no-cache
Last-Modified: Sat, 18 Jun 2011 19:40:24 GMT
Etag: "9c0a079bdd7701d7e729bd956823d153"
X-Ua-Compatible: IE=Edge,chrome=1
X-Runtime: 0.014243
X-Content-Digest: 501d6b0108b930264e19f37cb8ee6c8222d4f30d
Date: Sat, 18 Jun 2011 19:43:09 GMT
Age: 0
X-Rack-Cache: stale, valid, store
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close

�PNG

pngdata...
  • Comment out require "active_record/railtie" in application.rb.
  • If you run the server again now and GET /assets/rails.png it will work as above, so delete the tmp directory.
  • rails s -e production

Attempt to GET /assets/rails.png and it will return

HTTP/1.1 200 OK 
Content-Type: image/png
Content-Length: 0
Content-Md5: 9c0a079bdd7701d7e729bd956823d153
Cache-Control: public, must-revalidate
Last-Modified: Sat, 18 Jun 2011 19:40:24 GMT
Etag: "9c0a079bdd7701d7e729bd956823d153"
X-Ua-Compatible: IE=Edge,chrome=1
X-Sendfile: /Users/steve/projects/tmp/asset-pipeline-issue/app/assets/images/rails.png
X-Runtime: 0.042701
Date: Sat, 18 Jun 2011 19:46:55 GMT
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Age: 0
X-Rack-Cache: miss, store
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)
Connection: close

I think this is something to do with the connection middleware proxy that comes with activerecord, but that's just a guess.

stevehodgkiss added a commit to stevehodgkiss/rails that referenced this issue Jun 18, 2011

Fix inconsistencies by being polite to the wrapped body. Needed for R…
…ack::Sendfile to function properly. See issue #1761.
@stevehodgkiss

This comment has been minimized.

Show comment
Hide comment
@stevehodgkiss

stevehodgkiss Jun 18, 2011

Contributor

So the problem here was that in production mode, with active record, the asset pipeline would respond to paths without the cache buster (/assets/rails.png). This was because the active record proxy classes didn't respond to to_path, something which the rack sendfile middleware checks for.

Precompiled image asset work find in production, just not the ones that run through the asset pipeline (/assets/rails.png). It's probably an issue with my nginx config. config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" is set in production.rb, I've tried multiple configurations for passing the mapped path along, does anyone have this working with the asset pipeline? I don't see how the mapping would work given that there's not one fixed place where the file could be - proxy_set_header X-Accel-Mapping /var/www/=/files/;

Contributor

stevehodgkiss commented Jun 18, 2011

So the problem here was that in production mode, with active record, the asset pipeline would respond to paths without the cache buster (/assets/rails.png). This was because the active record proxy classes didn't respond to to_path, something which the rack sendfile middleware checks for.

Precompiled image asset work find in production, just not the ones that run through the asset pipeline (/assets/rails.png). It's probably an issue with my nginx config. config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" is set in production.rb, I've tried multiple configurations for passing the mapped path along, does anyone have this working with the asset pipeline? I don't see how the mapping would work given that there's not one fixed place where the file could be - proxy_set_header X-Accel-Mapping /var/www/=/files/;

stevehodgkiss added a commit to stevehodgkiss/rails that referenced this issue Jun 19, 2011

Fix inconsistencies by being polite to the wrapped body. Needed for R…
…ack::Sendfile to function properly. See issue #1761.
@stevehodgkiss

This comment has been minimized.

Show comment
Hide comment
@stevehodgkiss

stevehodgkiss Jun 19, 2011

Contributor

I needed to remove the cache /tmp on the production server for images to be served. No additional nginx configuration was needed for the sendfile middleware to work.

Contributor

stevehodgkiss commented Jun 19, 2011

I needed to remove the cache /tmp on the production server for images to be served. No additional nginx configuration was needed for the sendfile middleware to work.

@rhulse

This comment has been minimized.

Show comment
Hide comment
@rhulse

rhulse Jul 9, 2011

Contributor

Hi Steve, I am trying to sort bug 1822 and bisect converges on your commit. :-)

Using 3-1-stable (which requires spockets beta.10) I get 0 length image assets in development and production. Any ideas?

Contributor

rhulse commented Jul 9, 2011

Hi Steve, I am trying to sort bug 1822 and bisect converges on your commit. :-)

Using 3-1-stable (which requires spockets beta.10) I get 0 length image assets in development and production. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment