We're seeing transient issues when trying to generate a presigned url for an S3 object, via:
s3_object.presigned_url(:get, expires_in: 10.minutes)
The stacktrace:
NoMethodError: undefined method `credentials' for nil:NilClass
from aws-sdk-core/signers/v4.rb:45:in `initialize'
from aws-sdk-core/s3/presigner.rb:101:in `new'
from aws-sdk-core/s3/presigner.rb:101:in `block in sign_but_dont_send'
from aws-sdk-core/plugins/s3_request_signer.rb:88:in `call'
from aws-sdk-core/xml/error_handler.rb:8:in `call'
from aws-sdk-core/plugins/helpful_socket_errors.rb:10:in `call'
from aws-sdk-core/plugins/s3_request_signer.rb:65:in `call'
from aws-sdk-core/plugins/s3_redirects.rb:15:in `call'
from aws-sdk-core/plugins/retry_errors.rb:88:in `call'
from aws-sdk-core/plugins/s3_dualstack.rb:32:in `call'
from aws-sdk-core/plugins/s3_accelerate.rb:49:in `call'
from aws-sdk-core/plugins/s3_md5s.rb:31:in `call'
from aws-sdk-core/plugins/s3_expect_100_continue.rb:21:in `call'
from aws-sdk-core/plugins/s3_bucket_name_restrictions.rb:12:in `call'
from aws-sdk-core/plugins/s3_bucket_dns.rb:31:in `call'
from aws-sdk-core/rest/handler.rb:7:in `call'
from aws-sdk-core/plugins/user_agent.rb:12:in `call'
from seahorse/client/plugins/endpoint.rb:41:in `call'
from aws-sdk-core/plugins/param_validator.rb:21:in `call'
from seahorse/client/plugins/raise_response_errors.rb:14:in `call'
from aws-sdk-core/plugins/s3_sse_cpk.rb:19:in `call'
from aws-sdk-core/plugins/s3_dualstack.rb:24:in `call'
from aws-sdk-core/plugins/s3_accelerate.rb:34:in `call'
from aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
from aws-sdk-core/plugins/idempotency_token.rb:18:in `call'
from aws-sdk-core/plugins/param_converter.rb:20:in `call'
from seahorse/client/plugins/response_target.rb:21:in `call'
from seahorse/client/request.rb:70:in `send_request'
from aws-sdk-core/s3/presigner.rb:54:in `presigned_url'
from aws-sdk-resources/services/s3/object.rb:189:in `presigned_url'
aws-sdk 2.9.14,
ruby 2.2.3 / alpine 3.4 docker(https://github.com/gliderlabs/docker-alpine/blob/236558862619cbc7b7429c528d941b57692d85f3/versions/library-3.4/Dockerfile)
Hello @allcentury,
Is there a specific version and architecture of Alpine where you're seeing these transient issues?
I'm guessing you're running this in a multi-threaded environment - would that be right?
@awood45 yes we've seen the errors in active job and in web requests (via unicorn). @srchase thank you, i've added the info.
This is a known issue with version 2 of the SDK in multithreaded environments. You have a couple of options for resolving the issue. Essentially, version 2 of the SDK uses autoload which is not thread safe and can lead to race conditions in multi-threaded code.
Version 3 of the AWS SDK for Ruby is thread safe (it does not use autoload except for requiring whole services). It's also code compatible with V2 of the SDK, so it should only require changing your Gemfile and potentially some require lines.
The second option is to run the Aws.eager_autoload! method somewhere in your configuration/startup code. That will eagerly load all of the SDK files (and can be scoped down to just the services you use), and therefore you'll avoid race conditions.
Most helpful comment
This is a known issue with version 2 of the SDK in multithreaded environments. You have a couple of options for resolving the issue. Essentially, version 2 of the SDK uses
autoloadwhich is not thread safe and can lead to race conditions in multi-threaded code.Upgrade to Version 3
Version 3 of the AWS SDK for Ruby is thread safe (it does not use autoload except for requiring whole services). It's also code compatible with V2 of the SDK, so it should only require changing your
Gemfileand potentially somerequirelines.Workaround
The second option is to run the Aws.eager_autoload! method somewhere in your configuration/startup code. That will eagerly load all of the SDK files (and can be scoped down to just the services you use), and therefore you'll avoid race conditions.