Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange issue with 3.1, background jobs, Heroku and HTML email attachments (#117) #127

Closed
jontyD opened this issue May 24, 2017 · 6 comments
Assignees

Comments

@jontyD
Copy link

jontyD commented May 24, 2017

This seems to have re-occurred in rails 5.0.2, ruby 2.4.0
mime_types version 3.1

calling MIME::Types.of(filename) causes an error: undefined method sort' for nil:NilClass /app/vendor/bundle/ruby/2.4.0/gems/mime-types-3.1/lib/mime/types.rb:152:in type_for'
/app/vendor/bundle/ruby/2.4.0/gems/mime-types-3.1/lib/mime/types/registry.rb:32:in `type_for'

filename is some_name.pdf and is definitely present at this point

This works locally including in a local delayed job but on heroku worker in a delayed job I get this error which seems like issue 117

NB dj running as a daemon

@halostatue
Copy link
Member

… That‘s really weird. It’s pointed out something that I didn’t know ([].inject(:+) => nil), but the result array shouldn’t be empty because the extension index should be fully populated before this code gets run. This is going to take some time to figure out, and I’m afraid that I don’t see having that time in the next two weeks.

@johnsonj
Copy link

johnsonj commented Aug 8, 2017

I'm hitting this trying to update this code from mime-types 2.6.2 to 3.1 with ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux].

Will update if I find more info.

Stacktrace:

  1) VCAP::CloudController::BuildpacksController#delete with async false does not fail if no buildpack bits were ever uploaded
     Failure/Error: mime_type = MIME::Types.of(source_path).first.try(:content_type)
     
     NoMethodError:
       undefined method `sort' for nil:NilClass
     # /usr/local/google/home/jrjohnson/.rvm/gems/ruby-2.3.3/gems/mime-types-3.1/lib/mime/types.rb:152:in `type_for'
     # /usr/local/google/home/jrjohnson/.rvm/gems/ruby-2.3.3/gems/mime-types-3.1/lib/mime/types/registry.rb:32:in `type_for'
     # ./lib/cloud_controller/blobstore/fog/fog_client.rb:63:in `block in cp_to_blobstore'
     # ./lib/cloud_controller/blobstore/fog/fog_client.rb:59:in `open'
     # ./lib/cloud_controller/blobstore/fog/fog_client.rb:59:in `cp_to_blobstore'
     # ./lib/cloud_controller/blobstore/retryable_client.rb:48:in `block in cp_to_blobstore'
     # ./lib/cloud_controller/blobstore/retryable_client.rb:139:in `with_retries'
     # ./lib/cloud_controller/blobstore/retryable_client.rb:42:in `cp_to_blobstore'
     # ./lib/cloud_controller/blobstore/fog/error_handling_client.rb:55:in `block in cp_to_blobstore'
     # ./lib/cloud_controller/blobstore/fog/error_handling_client.rb:61:in `error_handling'
     # ./lib/cloud_controller/blobstore/fog/error_handling_client.rb:55:in `cp_to_blobstore'
     # ./spec/unit/controllers/runtime/buildpacks_controller_spec.rb:143:in `block (4 levels) in <module:CloudController>'

Repro:

  1. Clone my fork
git clone https://github.com/johnsonj/cloud_controller_ng
cd cloud_controller_ng
  1. Create postgres user/database:
sudo -u postgres psql -c "create user pguser with password 'pguser' superuser;"
sudo -u postgres psql -c "create database cc_test;"
  1. Run spec:
DB=postgres PGPASSWORD="pguser" PGUSER="pguser" bundle exec rspec spec/unit/controllers/runtime/buildpacks_controller_spec.rb

@FX-HAO
Copy link

FX-HAO commented Aug 11, 2017

+1

@johnsonj
Copy link

johnsonj commented Aug 15, 2017

In our case the issue isn't that @extensions_index is nil, it's that we were passing in a bad parameter that it was previously quiet about.

The calling code essentially did this:

  MIME::Types.of(Tempfile.new).first.try(:content_type)

Which is used to create an empty array inside of type_for

  a = Array(Tempfile.new) # => []
  a.flat_map { |fn| puts 'never called!'; fn } # => []
  a.compact # => []
  a.inject(:+) # => nil

So ruby learnings from this bug:

  • [].inject(:+) => nil
  • [Tempfile.new] != Array(Tempfile.new)

johnsonj added a commit to johnsonj/cloud_controller_ng that referenced this issue Aug 15, 2017
@halostatue
Copy link
Member

This is because Array(Tempfile.new) calls Tempfile#to_a, delegated from File#to_a via Enumerable#to_a.

Sounds like I might need to go back to [arg].flatten instead of Array(arg).

@halostatue halostatue self-assigned this Aug 15, 2017
johnsonj added a commit to johnsonj/cloud_controller_ng that referenced this issue Jan 8, 2018
johnsonj added a commit to johnsonj/cloud_controller_ng that referenced this issue Jan 8, 2018
halostatue added a commit that referenced this issue Aug 12, 2018
@halostatue
Copy link
Member

Resolved with edf3cd7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants