TypeError: can't dump File

400 views
Skip to first unread message

Francois

unread,
May 6, 2011, 6:32:38 PM5/6/11
to Refinery CMS
When editing pages on my heroku hosted refinery app I'm seeing the
following error:

TypeError: can't dump File

if I do a page refresh after this error occurs then the page updates
successfully completes without error.

The error does not seem to happen in development and it only started
happening once I upgraded my app from 0.9.9.4 to 0.9.9.21

I'm sure I'll eventually track it down but just thought I would ask in
case anyone here has seen this before.

- thanks,
Francois

Francois

unread,
May 6, 2011, 6:52:16 PM5/6/11
to Refinery CMS
Here is a bit more info:

hoptoadapp is reporting that the error occurs on the following file/
line:

.bundle/gems/ruby/1.8/gems/activesupport-3.0.7/lib/active_support/
cache.rb:621

the controller/action is admin/pages#update


Francois

unread,
May 6, 2011, 7:02:07 PM5/6/11
to Refinery CMS
Problem partly solved. Turning off the 'cache menu' setting makes the
problem go away.


Francois

unread,
May 6, 2011, 8:40:56 PM5/6/11
to Refinery CMS
the cause of the problem is the following call in page.rb

Rails.cache.delete_matched(/.*pages.*/)

for some reason that call sometimes works on heroku but at other times
it does not work and returns 'TypeError: can't dump File'.
I'm not sure if this is a bug in Rails 3 caching or if it is a heroku
bug.

- F

Francois

unread,
May 6, 2011, 9:17:12 PM5/6/11
to Refinery CMS

after a bit more digging:

Rails.cache.fetch('refinery_pages_menus_menu_en') works fine

but

Rails.cache.delete('refinery_pages_menus_menu_en') will cause the
"TypeError: can't dump File" error.

still not sure if this is a rails 3 issue, a heroku issue, or a
refinery issue.







Philip Arndt

unread,
May 6, 2011, 9:20:06 PM5/6/11
to refine...@googlegroups.com
Is your cache set to memory_store ?

Francois

unread,
May 7, 2011, 1:09:03 AM5/7/11
to Refinery CMS
I haven't changed any of the cache_store settings so I'm using
whatever the default is.

I just went into the heroku console and entered Rails.cache and I get
the following output:
<#ActiveSupport::Cache::MemoryStore entries=36, size=365601, options={}
>

so that looks like I am using memory_store

As far as I can tell the problem occurs because the size method in
cache.rb (ActiveSupport 3.0.7) gets called when a cache entry is
deleted. And if a cache entry doesn't have a bytesize method then the
size of the cache entry is calculated using
Marshal.dump(@value).bytesize (line 621 of cache.rb) and Marshal.dump
craps out because it does not know how to marshal all those page
classes.

The rails guide for for caching makes the following claim
"MemoryStore is not only able to store strings, but also arbitrary
Ruby objects."

If that statement is true, then this would seem to be a bug in Rails
3.0.7 because memorystore is assuming that the bytesize of an object
can always be calculated using Marshal.dump(@value).bytesize



- Francois

Philip Arndt

unread,
May 7, 2011, 1:10:16 AM5/7/11
to refine...@googlegroups.com
You're right, it does sound like a bug in Rails. I don't think we're doing anything particularly special as far as caching.

Good sleuthing!

Francois

unread,
May 7, 2011, 1:28:41 AM5/7/11
to Refinery CMS
ok, its a bit more complicated than I expected:

From the heroku console I did the following:

> pages = Rails.cache.fetch('refinery_pages_menus_menu_en')
> pages.count
=> 11
> p = pages.last
> Marshal.dump(p)
TypeError: can't dump File
> p.id
11
> p2 = Page.find 11
> p2 == p
=> true
> Marshal.dump(p2)
=> "\004\bo:\tPage\r:\016@readonlyF:\017@destroyedF:
\020@attributes{\025\"\030skip_to_first_child\"\006f\"\rposition
\"\0065\"\017created_at\"\0372011-03-30
20:40:14.450897\"\ndepth0\"\ndraft\"\006f\"\021show_in_menu\"\006t
\"\017updated_at\"\0372011-05-04 18:24:09.750244\"\blft\"\a23\"\aid
\"\a11\"\026custom_title_type\"\tnone\"\016deletable\"\006f
\"\017menu_match\"\035^/(inquiries|contact).*$
\"\tpath0\"\016parent_id0\"\brgt\"\a28\"\rlink_url\"\r/contact:
\030@changed_attributes{\000:\020@new_recordF:
\030@previously_changed{\000:\026@attributes_cache{\a
\"\017created_atU: ActiveSupport::TimeWithZone[\bu:\tTime\r??\e?Q??
\"\bUTC@*\"\017updated_atU;\r[\bu;\016\r\222??r\233`@+@/:
\034@marked_for_destructionF"
>
> Marshal.dump(p)
=> TypeError: can't dump File
> p.reload
> Marshal.dump(p) # now it works
=> "\004\bo:\tPage\025:\016@readonlyF:
\v@parts0:\016@children0:\017@destroyedF: (output cropped)

- Francois

Francois

unread,
May 7, 2011, 3:06:11 AM5/7/11
to Refinery CMS
i switched to using memcache as the cache store on heroku and that
seems to make things happy.

I couldn't quite get to the bottom of the problem with using the
memory_store. It sometimes works and sometimes doesn't. I'm going to
leave it for now and maybe look at it again at a later time.

- Francois

Francois

unread,
May 7, 2011, 8:21:29 PM5/7/11
to Refinery CMS
I was looking over the documentation on heroku's website today and
found the following statement:

"Fragment caching uses (and requires) the Heroku Memcache add-on."


So I think the bottom line is that one needs to use the memcache add-
on (5 MB is free) if one wants to cache the menu (Cache Menu => true)
And menu caching does seem to improve page loading on Heroku quite
noticeably.

I'll add a note to the heroku guide about this.

- Francois
Reply all
Reply to author
Forward
0 new messages