I am attempting to memcache an ActiveRecord results array, which I have manually filtered based on some complex business rules. After an upgrade today I'm getting a nasty error based on Dalli attempting to serialize the array and failing with the following error:
Marshalling error for key 'workcases/index/1570/true/c1...:md5:64db5952f959c45126399dd4cb113f86': can't dump UNIXSocket
in .../gems/dalli-2.6.4/lib/dalli/server.rb:397:in `dump'
This was not happening before upgrading from Ruby 1.9.3 to Ruby 2.0.0 and an associated upgrade of Passenger to 4.0.7 (previously 4.0.5).
The environment:
- Ruby 2.0.0-p247
- Rails 3.2.13
- Dalli gem 2.6.4
- Passenger 4.0.7
A snippet of the code, removing a lot of the complexity that is unrelated to this issue
# The query and filter
def do_query
workcases = Workcase.all(:select=>"#{straight_join} distinct
workcases.id, workcases.caseId, workcases.subject
service_case_types.primary_level, service_case_types.hide_in_result_list #{extra_fields}",
:conditions => conditions, :joins=>joins, :order=>order )
for workcase in workcases
if user.can_view_workcase?(workcase, options)
workcases_filtered << workcase
res_count+=1
end
break if limit && res_count >= limit
end
workcases_filtered
end
# In the Controller
def index
...
@workcases = Rails.cache.fetch(cid, :expires_in=>expires) do
Rails.logger.info "Populating cache for workcases in search"
ActiveRecord::Base.uncached do
Workcase.do_query(@user, in_summary_list, order, nil, true, !@show_deleted_items, condition_ary, @list_limit, {:service_id=>service_id, :case_type_id=>case_type_id})
end
end
...
end
The reason for pushing the full query result set into the cache is the time it takes to run the business logic for filtering the database results to handle complex user security / access control requirements. So, I understand that this may not be the preferred use of a cache in Rails, but up until yesterday it was working like a dream. I'm really not looking for answers like 'just cache the primary keys', since I'll just not bother caching at all.
Extra note:
I attempted to roll back to Ruby 1.9.3 (using RVM, and rebundled the app) and the error did not go away. In my development environment, using Webrick and otherwise equivalent ruby and gem versions I do not see this error.
I would like to know:
- where is the UNIXSocket coming from?
- any clues how to debug this (I have reviewed the instances being cached and there are no procs in there
- whether there is an issue with associations or joins that have suddenly appeared in Marshal or Dalli
- does Passenger affect the operation of Dalli and/or Marshal?
In fact any thoughts would be appreciated at this point.
EDIT
I have attempted rolling back to an earlier version of the passenger gem and that did not help. I also tried rvm with an earlier version of Ruby 1.9.3 and that also did not solve it. I don't believe that the Dalli gem changed between updates.
Also note, other queries are writing to memcache successfully.