2
votes

I keep having a problem of rails crashing when accessing attached image files. At least I think it's that.

I have no idea how to figure out what the actual problem is.

I notice there's some crash info about belongs_to_association but I'm not sure if that's a related issue or it's to do with active storage. I tried switch json serializer but have the same problem.

Ruby: 2.5.5 Rails: 6.0.0 (same error with previous version) Accessed through ember.js frontend.

Model:

class Boat < ApplicationRecord
  has_many :histories
  has_and_belongs_to_many :boat_collection
  has_many_attached :images
  has_one_attached :thumbnail
end
  • only using thumbnails at the moment

Serializer:

module BoatHelper
  extend ActiveSupport::Concern
  include Rails.application.routes.url_helpers

  class_methods do
    def thumbnail_url(object)
      Rails.application.routes.url_helpers.rails_blob_url(object.thumbnail, :host => 'localhost:3000') if object.thumbnail.attachment
    end
  end
end

class BoatSerializer < ActiveModel::Serializer
  include FastJsonapi::ObjectSerializer
  include BoatHelper

  set_key_transform :dash

  attributes :id, :listing_title, :url, :price, :currency, :first_found, :listing_id, :total_inches, :country, :state, :city, :year, :make, :model, :cabins, :latitude, :longitude, :location, :title
  # has_and_belongs_to_many :boat_collection

  attribute :thumbnail do |object|
    thumbnail_url(object)
  end
end

Controller:

def index
  @boats = Boat.all
  render json: BoatSerializer.new(@boats).serialized_json
end

Crash info:

Started GET "/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBaXdFIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--0891bcd5249ef8908c621dfb51faa206dcbfcde6/thumbnail-yachthub-237523.jpg" for ::1 at 2019-09-08 13:05:24 +1000
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/puma-3.12.1/lib/puma/client.rb:315: [BUG] object allocation during garbage collection phase
ruby 2.5.5p157 (2019-03-15 revision 67260) [x64-mingw32]

 1436 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/builder/has_and_belongs_to_many.rb
 1437 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/builder/belongs_to.rb
 1438 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/association.rb
 1439 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/singular_association.rb
 1440 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/foreign_association.rb
 1441 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/has_one_association.rb
 1442 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/association_scope.rb
 1443 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/alias_tracker.rb
 1444 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/statement_cache.rb
 1445 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/belongs_to_association.rb
 1446 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/associations/belongs_to_polymorphic_association.rb
 1447 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activestorage-6.0.0/lib/active_storage/downloader.rb
 1448 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activestorage-6.0.0/lib/active_storage/analyzer/null_analyzer.rb
 1449 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activerecord-6.0.0/lib/active_record/coders/json.rb
 1450 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activestorage-6.0.0/lib/active_storage/log_subscriber.rb
 1451 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activestorage-6.0.0/lib/active_storage/service.rb
 1452 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activestorage-6.0.0/lib/active_storage/service/configurator.rb
 1453 C:/Ruby25-x64/lib/ruby/2.5.0/x64-mingw32/digest/md5.so
 1454 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activestorage-6.0.0/lib/active_storage/service/disk_service.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
1
That looks like an actual bug in the rails source code rather than an issue you've created - might be worth raising a ticket with them - guides.rubyonrails.org/…Mark

1 Answers

1
votes

Ruby: 2.5.5 Rails: 6.0.0 I had the same issue, fixed it by uninstalling Ruby and installing 2.6.5