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

Rails 7, GCS Error performing ActiveStorage::AnalyzeJob 'NoMethodError (undefined method `header' for nil)' #25670

Open
cmbaldwin opened this issue Apr 7, 2024 · 1 comment
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@cmbaldwin
Copy link

cmbaldwin commented Apr 7, 2024

Array(resp.header["Content-Encoding"]).include?("gzip")

I'm in a development environment running Sidekiq for ActiveJob. I am uploading an image to GCS, and while the upload appears to be working, I get an error in the background process with Sidekiq:

2024-04-07T22:26:12.045Z pid=83252 tid=9g0 INFO: Performing ActiveStorage::AnalyzeJob (Job ID: 6577da28-1888-4829-9555-15713470c9be) from Sidekiq(default) enqueued at 2024-04-07T22:25:23.428248000Z with arguments: #<GlobalID:0x000000014185d440 @uri=#<URI::GID gid://funabiki-online/ActiveStorage::Blob/19959>> 2024-04-07T22:26:12.196Z pid=83252 tid=9g0 INFO: GCS Storage (148.7ms) Downloaded file from key: pxzjm0zpghoz066siyph4gfoa4yi 2024-04-07T22:26:12.197Z pid=83252 tid=9g0 ERROR: Error performing ActiveStorage::AnalyzeJob (Job ID: 6577da28-1888-4829-9555-15713470c9be) from Sidekiq(default) in 175.79ms: NoMethodError (undefined method header' for nil):
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/google-cloud-storage-1.49.0/lib/google/cloud/storage/file.rb:1054:in download' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/service/gcs_service.rb:186:in stream'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/service/gcs_service.rb:37:in block in download' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.2/lib/active_support/notifications.rb:206:in block in instrument'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.2/lib/active_support/notifications/instrumenter.rb:58:in instrument' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3.2/lib/active_support/notifications.rb:206:in instrument'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/service.rb:165:in instrument' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/service/gcs_service.rb:36:in download'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/downloader.rb:32:in download' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/downloader.rb:13:in block in open'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/downloader.rb:24:in open_tempfile' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/downloader.rb:12:in open'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/service.rb:92:in open' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/app/models/active_storage/blob.rb:290:in open'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/analyzer.rb:35:in download_blob_to_tempfile' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/analyzer/image_analyzer/vips.rb:20:in read_image'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/lib/active_storage/analyzer/image_analyzer.rb:20:in metadata' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/app/models/active_storage/blob/analyzable.rb:52:in extract_metadata_via_analyzer'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/app/models/active_storage/blob/analyzable.rb:30:in analyze' */.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activestorage-7.1.3.2/app/jobs/active_storage/analyze_job.rb:11:in perform'
*/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activejob-7.1.3.2/lib/active_job/execution.rb:69:in block in _perform_job'

Tracing it back to:

def download_file bucket_name, file_path, target_path, generation: nil,

This download_file call is resulting in 'nil'. But, if I go into IRB and check, the file is correctly attached to my model and I can get an url that is accessible. Likewise, in my dev environment the image loads and the record has be persisted. It's just this Analyze callback that is causing issues. I thought it was a race conditions error so I tried setting Sidekiq to inline processing but the issue still comes up (this time returning an error to the user instead of within the Sidekiq background process).

I wasn't sure exactly where to post this, as various gems are involved (ActiveStorage, SideKiq, ActiveJob, GCS), so thanks in advance if you're reading this.

[edit:] Confirmed error in production as well. I have been uploading PDFs in the past, and jpgs and haven't had problems.

@shivgautam shivgautam added the api: storage Issues related to the Cloud Storage API. label Apr 10, 2024
@shivgautam shivgautam assigned bajajneha27 and unassigned aandreassa Apr 10, 2024
@cmbaldwin
Copy link
Author

cmbaldwin commented Apr 25, 2024

I am downgrading as the post suggests, but I also have the error described here:
https://stackoverflow.com/questions/78370556/ruby-on-rails-error-unknown-keyword-soft-deleted-when-download-file-with-go

I think he was having the same error as me. It was being fed to sidekiq or some background async service, and then the analysis was failing and soft_deleting the file, hence the related error here. I could be wrong, but this also popped up a few days ago, so I suspect it's related.

Confirmed that downgrading to 1.37.0 fixed this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

No branches or pull requests

4 participants