rtomayko / rack-cache

Real HTTP Caching for Ruby Web Apps

Home Page:http://rtomayko.github.io/rack-cache/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with Dragonfly Gem after upgrading to 1.6.0

krisdigital opened this issue · comments

After upgrading to 1.6.0 images are not rendered anymore using Dragonfly Gem and rack-cache. 1.5.1 does work.

@grosser and @amatriain do you have an idea what may have caused this? Would help fixing the issue..

App 11445 stderr: [ 2016-02-10 18:04:27.6602 11546/0x007f958a883098(Worker 1) utils.rb:87 ]: *** Exception Dragonfly::TempObject::Closed in Rack response body object (can't read from tempfile as TempObject has been closed) (process 11546, thread 0x007f958a883098(Worker 1)):
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:179:in `tempfile'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:89:in `file'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:137:in `to_io'
[ 2016-02-10 18:04:27.6606 11440/0x700000290000 age/Cor/Req/ForwardResponse.cpp:169 ]: [Client 2-7] Application sent EOF before finishing response body: 0 bytes already read, 44174 bytes expected
[ 2016-02-10 18:04:27.6608 11440/0x700000290000 Ser/Server.h:936 ]: [Client 2-7] Disconnecting client with error: application did not send a complete response
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:111:in `each'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 11445 stderr:   from /home/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'

Could you provide a test case?

Here comes the test case!

https://github.com/krisdigital/rack_cache_1_6_dragonfly_test_case

The error seems only to occur if the item is not cached. That is why I clear the cache before the test..

You should see an output like the following when running rake test

# Running:

Get URL /media/W1siZmYiLCJmaWxlcy9CbGFjay1TYWJiYXRoLUluLVRoZS03MHMtSGQtV2FsbHBhcGVyLmpwZyJdLFsicCIsInRodW1iIiwiMTAweDEwMCMiXV0/Black-Sabbath-In-The-70s-Hd-Wallpaper.jpg?sha=42c191756e0fa7f6
E

Finished in 0.244711s, 4.0865 runs/s, 0.0000 assertions/s.

  1) Error:
RackCache16DragonflyTest#test_Test_Dragonfly_with_rack_cache:
Dragonfly::TempObject::Closed: can't read from tempfile as TempObject has been closed
    test/integration/rack_cache_1_6_dragonfly_test.rb:17:in `block in <class:RackCache16DragonflyTest>'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

full backtrace ... something deep inside of dragonfly :(

  1) Error:
RackCache16DragonflyTest#test_Test_Dragonfly_with_rack_cache:
Dragonfly::TempObject::Closed: can't read from tempfile as TempObject has been closed
    vendor/bundle/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:179:in `tempfile'
    vendor/bundle/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:89:in `file'
    vendor/bundle/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:137:in `to_io'
    vendor/bundle/gems/dragonfly-1.0.12/lib/dragonfly/temp_object.rb:111:in `each'
    vendor/bundle/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
    vendor/bundle/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
    vendor/bundle/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
    vendor/bundle/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
    vendor/bundle/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
    vendor/bundle/gems/rack-1.6.4/lib/rack/response.rb:39:in `initialize'
    vendor/bundle/gems/rack-1.6.4/lib/rack/mock.rb:169:in `initialize'
    vendor/bundle/gems/rack-test-0.6.3/lib/rack/mock_session.rb:32:in `new'
    vendor/bundle/gems/rack-test-0.6.3/lib/rack/mock_session.rb:32:in `request'
    vendor/bundle/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
    vendor/bundle/gems/rack-test-0.6.3/lib/rack/test.rb:124:in `request'
    vendor/bundle/gems/actionpack-4.2.5.1/lib/action_dispatch/testing/integration.rb:297:in `process'
    vendor/bundle/gems/actionpack-4.2.5.1/lib/action_dispatch/testing/integration.rb:32:in `get'
    vendor/bundle/gems/actionpack-4.2.5.1/lib/action_dispatch/testing/integration.rb:346:in `block (2 levels) in <module:Runner>'
    ./test/integration/rack_cache_1_6_dragonfly_test.rb:15:in `block in <class:RackCache16DragonflyTest>'

reverting #133 fixes it ...

entity_store.open(digest) returns #Rack::Cache::EntityStore::Disk::Body:0x007fe4129bf8e0 which then can be read ... but request.body cannot ...

doing response.body = response.body.to_s also works

eliminating the rack-cacke middleware also fixes the problem ...

so I think what happens is that the body is set to the TempObject ... and we read it, but then it gets read again when the body is returned to the browser and it blows up ...

removing the 'storage' part of rack-cache also fixes the issue ...

because ... entitystore closes the body ... removing that solves the issue

I'll open a PR and see how much that blows up / if I can add a failing test

thx for the repro-repo, that was very helpful :)
fix coming in #135

yanked 1.6.0 for good measure

@grosser Thank you for the quick reply and fix!